|
The problem is in the remoting portion of the service itself.
The service looks like:
<br />
public class MyService : System.ServiceProcess.ServiceBase<br />
{<br />
private m_sString = "hello";<br />
...<br />
protected override void OnStart(string[] args)<br />
{<br />
RemotingConfiguration.Configure("RemotingServer.Config");<br />
}<br />
...<br />
public string StringFunction()<br />
{<br />
return m_sString;<br />
}<br />
...<br />
}<br />
And uses the following RemotingServer.config:
<br />
<configuration><br />
<system.runtime.remoting><br />
<application><br />
<service><br />
<wellknown <br />
mode="SingleCall" <br />
type="MyService,Tools.MyService" <br />
objectUri="MyService.rem"<br />
/><br />
</service><br />
<channels><br />
<channel ref="http" port="8500"/><br />
</channels><br />
</application><br />
</system.runtime.remoting><br />
</configuration><br />
The client looks like this:
<br />
MyService remoteObject = (MyService) Activator.GetObject(typeof(MyService), "http://localhost:8500/RemotingClient.rem");<br />
string sRetVal = remoteObject.StringFunction();<br />
The client RemotingClient.rem file looks like:
<br />
<configuration><br />
<system.runtime.remoting><br />
<application><br />
<client><br />
<wellknown <br />
type="MyService, Tools.MyService"<br />
url="http://localhost:8500/MyService.rem"<br />
/><br />
</client><br />
</application><br />
</system.runtime.remoting><br />
</configuration><br />
The error I receive is:
<br />
An unhandled exception of type 'System.Net.WebException' occurred in mscorlib.dll<br />
<br />
Additional information: The underlying connection was closed: Unable to connect to the remote server.<br />
The client code is sitting in an console app.
The service starts and reports it is running correctly. It is compiled as a DLL.
|
|
|
|
|
I am sorry I have not replied quickly. There are several problems to consider in the approach you have. You can't remote your whole service like you are trying to do. Instead, put your code in a class (preferably in a new class library project). The class must inherit from MarshalByRefObject to be remoted. Also, the "type" attribute in your config files should be in the form type="namespace.class,assemblyname". It looks like you have it backwards.
Also, when you write the client app, you can add a reference to your remote class, but is generally looked upon as bad practice. It will work though for learning about remoting. After you become more comfortable, there are other ways of referencing your remote objects in the client such as implementing an interface in the remote code, and only referring to the interface in the client code. There are also ways to make a meta data assembly using soapsuds to extract the definitions from the remote object, then compiling an assembly using the output from soapsuds. For now, just keep that in the back of your mind to explore after you get romoting to work in the most simple case.
1. Make a new class library project (call it HelloWorld or something).
a. Add a Class called HelloWorldInfo or something.
1. Make sure it inherits from MarshalByRefObject
2. Make a console project to act as a test server (call it MyServer).
a. Add a reference in MyServer to HelloWorld.
b. Add a config file to MyServer and add the remoting config to it.
c. In Main(), call the remoting configuration, and then wait for a keypress.
3. Make a console project to act as a client to the server.
a. Add a reference to HelloWorld (this is not good practice, but will serve as a simple way during learning).
b. Add a config file and put the client remoting config in it.
c. In Main(), call the remoting configuration, then call any methods you want and output the results to the console.
4. Debug the server by starting it in Visual Studio
a. Open a command prompt and type "netstat -a"
b. look in the list output from netstat for the port you have assigned to your remote object. You should see your computer listening on that port.
5. Open your client in another copy of Visual Studio and start it for debugging.
a. You can now step through your code in debug mode, and even step into the server code. This makes debugging much easier.
6. Once the server code is fully debugged, Make a new windows service project.
a. Add a reference to HelloWorld.
b. Put the remoting configuration code in the OnStart of your service.
c. Add an installer to your service.
d. Add a setup project to install your service.
After you get comfortable with remoting, be sure to go back and learn how to reference remote classes in the remote client without deploying the server code to the client (so it by implementing interfaces, or compiling metadata-only assemblies).
|
|
|
|
|
Hi,
I had trouble about flickering effect on an MDI form. I'd built my own control, which is moveable by draging, and also overrided the paint event. It was very well in a normal form but unfortunately disappeared in MDI form. Even some of the codes provided here have the same problem. What is handle the MDI form painting event? Is it different from the normal one? And how could I fix such a problem?
Thanks in advance.
|
|
|
|
|
There's nothing different about an MDI Form being painted. There is no seperate event for painting either.
Is your control on the MDI Parent form? Did you know that there is a MDIClient control on the Parent form? Is you control in the Controls collection of the MDIParent or the MDIClient? If it's the MDIParent, your control is probably being painted over by the MDIClient area control.
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
Is there a way to import regirtry files within C#?
this way i could update some settings myself, and then in C# just open up the registry to the necessary folder and import the files. This would save alot of messing around and i would be able to use the peice of code again.
Any ideas?
|
|
|
|
|
This is an example of a file exported from regedit:
Windows Registry Editor Version 5.00
[HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\FileExts\.ppt]
[HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\FileExts\.ppt\OpenWithProgids]
"PowerPoint.Show.8"=hex(0):
this is just for the file extension .ppt
Is there any way that i can use this?
|
|
|
|
|
I am not sure how this is done. I have been doing some searching and reading and I can't seem to get this to work. I am really bad with terminology, but if someone could point me in the right direction I would bw greatful...
Thanks,
Eric Garcia
|
|
|
|
|
Ok, just pass the textbox instance to the other class's constructor or a method in that class. For instance,
class ClassWithTextBox
{
private TextBox myTextBox = new TextBox();
ClassWithoutTextBox classWithout = new ClassWithoutTextBox();
classWithout.ChangeTextboxColor(myTextBox);
}
class ClassWithoutTextBox
{
void ChangeTextboxColor(TextBox textBoxToModify)
{
textBoxToModify.BackColor = Color.Red;
}
}
Tech, life, family, faith: Give me a visit.
I'm currently blogging about: Hallelujah! It's Ken Jennings!
Judah Himango
|
|
|
|
|
Here is a better explination...
private void FollowLink(object parameters)
{
CMTag_Spider.SpiderForm spiderform;
//Other code here
spiderform.txtOuput.AppendText("/tLink:" + link.AbsolutePath);
//Other code here
}
compiler:
Use of unassigned local variable 'spiderform'(CS0165)
The situation I have is that I am using a c# webspider class and calling it from a form I named SpiderForm. Because of the way the Spider was coded I am not sure that I want to make too many changed to it.
I thought there was a way to declare a form and then set that to the active form and then as long as the textbox was public I could access it.
What I am not sure about is how to assign the spiderform variable...
Thanks for the help,
|
|
|
|
|
Assign it by taking an instance of the class that actually contains the spiderform object, then accessing that variable (provided it's public). Another option is to make the variable static and public, then you don't need an instance of the class to access it.
Tech, life, family, faith: Give me a visit.
I'm currently blogging about: Hallelujah! It's Ken Jennings!
Judah Himango
|
|
|
|
|
I have a program I am writing for my own personl use that takes an XML file and interprets it into a treeview, then if a secion is clicked it shows the information between the tags in a textbox. The problem im having is with this peice of code.
XmlTextReader document = initializeXmlReader();
while((document.Name != e.Node.Tag.ToString()) && (document.GetAttribute("Name")!= e.Node.Text))
{
document.Read();
}
All the tree nodes are made up of the elemets attributes, this code works partially to go through the document and find if the right attribute, but sometimes it returns null, and does not display the next catagory's text.
Here is some sample XML.
<?xml version="1.0" encoding="utf-8" ?>
<Main Name="Desktop Sidebar Help">
<![CDATA[ TEST TEST TEST ]]>
<Key_Cat Name="Overview">
<Sub_Topic Name="Context Menu">TestTestTest</Sub_Topic>
<Sub_Topic Name="Options"></Sub_Topic>
</Key_Cat>
<Key_Cat Name="Basic Panels">
<Sub_Cat Name="Communication">
<Key_Topic Name="Mail Checker Panel">
</Key_Topic>
<Key_Topic Name="Messenger Panel">
</Key_Topic>
<Key_Topic Name="Miranda IM">
</Key_Topic>
</Sub_Cat>
<Sub_Cat Name="Groups Panels">
<Key_Topic Name="Stack Group">
</Key_Topic>
<Key_Topic Name="Tile Group">
</Key_Topic>
</Sub_Cat>
<Sub_Cat Name="Media"></Sub_Cat>
<Sub_Cat Name="News"></Sub_Cat>
<Sub_Cat Name="Outlook Panels"></Sub_Cat>
<Sub_Cat Name="System"></Sub_Cat>
</Key_Cat>
<Key_Cat Name="3rd Party Panels">
<Sub_Cat Name="Media"></Sub_Cat>
<Sub_Cat Name="Media"></Sub_Cat>
<Sub_Cat Name="Media"></Sub_Cat>
<Sub_Cat Name="Media"></Sub_Cat>
</Key_Cat>
<Key_Cat Name="Skin Development">
<Sub_Cat Name="Media"></Sub_Cat>
<Sub_Cat Name="Media"></Sub_Cat>
<Sub_Cat Name="Media"></Sub_Cat>
</Key_Cat>
<Key_Cat Name="Plugin Development">
<Sub_Cat Name="DS SDK Documentation Forum - About"></Sub_Cat>
<Sub_Cat Name="Creating/Adding a Panel">
<Key_Topic Name="Creating an Empty Panel"></Key_Topic>
<Key_Topic Name="Adding Your Panel to Desktop Sidebar">trdtfgrgbergbergbergber</Key_Topic>
</Sub_Cat>
<Sub_Cat Name="Creating a Panel Installation File "></Sub_Cat>
<Sub_Cat Name="Publishing Your Panel"></Sub_Cat>
<Sub_Cat Name="Using Components"></Sub_Cat>
<Sub_Cat Name="Reference"></Sub_Cat>
<Sub_Cat Name="FAQ"></Sub_Cat>
</Key_Cat>
<Key_Cat Name="FAQ">
<Sub_Cat Name="Media"></Sub_Cat>
<Sub_Cat Name="Media"></Sub_Cat>
<Sub_Cat Name="Media"></Sub_Cat>
</Key_Cat>
<Key_Cat Name="Universal Help Engine">
<Sub_Cat Name="Media"></Sub_Cat>
<Sub_Cat Name="Media"></Sub_Cat>
<Sub_Cat Name="Media"></Sub_Cat>
<Sub_Cat Name="Media"></Sub_Cat>
</Key_Cat>
<Key_Cat Name="About Universal Help Engine">
<Sub_Cat Name="Media"></Sub_Cat>
<Sub_Cat Name="Media"></Sub_Cat>
<Sub_Cat Name="Media"></Sub_Cat>
<Sub_Cat Name="Media">TESTTESTTEST</Sub_Cat>
</Key_Cat>
<Location ID="http://"><Location>
</Main>
I've been testing it by just clicking the first few treenodes that have a different attribute. But most of the time only one or two will work before it is just stays on the same thing for anything else I click. This is really bothering me. I edited out the text that was inbetween the tags, for length problems in this posting.
Sample of what its doing.
Tree
Desktop Sidebar
--OverView
---Context
---Options
--BasicPanels
---Communication
----Mail Checker Panel
----Messanger Panel
----Miranda IM
and so on
When I click mail checker panel for instance, it will show up right. But then if I click messanger Panel, it will show up with Main Check Panels text instead of Messanger Panels Text, upon debugging I noticed that getattribute is returnning null sometimes, I beleive this is the problem. The text between the tags will, contain HTML which is parsed by the textbox/web browser i've incorpertaited.
Any help would be much apperiated. Also if more code is needed I can post it.
|
|
|
|
|
In general when I know exactly the keywords(about 300) I want to find should I use something like:
1)Regex(@"if|do|for|while|int|Int32|Int64...(about 300)") or
2)Regex(@"[_A-Za-z]+[A-Za-z]\w*] and follows searching in a hashtable?
|
|
|
|
|
Option 2 would be preferable, speed and maintainability are the biggest benefits.
Option 1 is simply out of the question. That's just a nightmare waiting to bite you.
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
|
I have been banging my head against the wall on this for a couple of hours now.
I work with SQL usually and have that down to an artform, but i am working on a project that requires me to insert info into an access db, and i am trying like hell just to get a simple statement to work, but i cant find a hting in msdn or on the internet. Any suggestions?
______________________
Yes, I am the highly suggestable type.
|
|
|
|
|
What's the statement your trying to get working?
Keep in mind that Jet doesn't support named parameters, but it does support parameters. You just have to supply them in the exact same order that they appear in your SQL statement. Also, Jet doesn't support the full range of SQL syntax that SQL Server does.
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
here is the code I am attempting to use:
string strConn = "Provider=Microsoft.Jet.OLEDB.4.0;" + "Data Source=" + DS + ";";<br />
string comma = "INSERT INTO comments (page,who,comment,email) VALUES (" + page + "," + name + "," + comments + "," + mail + ")";<br />
OleDbConnection con = new OleDbConnection(strConn);<br />
OleDbDataAdapter da = new OleDbDataAdapter(comma,con);<br />
OleDbCommand cmd;<br />
cmd = new OleDbCommand(comma, con);<br />
<br />
con.Open();<br />
cmd.ExecuteNonQuery();<br />
con.Close();
______________________
Yes, I am the highly suggestable type.
|
|
|
|
|
Looking at your code I can't see why it doesnt work.
I do have a couple of suggestions that might help.
1. The OleDbDataAdapter is not required to execute a simple command it is only required when performing operations on datsets.
2. I would use parameters instead of hard coding the values into your command string, problems will occur if you have special characters in the varaiables such as quota marks. To do this the code will look something like below. (NOTE: You need to set the appropriate varaibale types for each parameter, I have guessed at what they might be)
3. I would recommend enclosing field names in square brackets as some words are reserved, see below.
string comma = "INSERT INTO comments([page],[who],[comment],[email]) VALUES (paramPage, paramName, paramComment, paramMail);"
OleDbConnection con = new OleDbConnection(strConn);
OleDbCommand cmd = new OleDbCommand(comma, con);
cmd.Parameters.Add("paramPage", OleDbType.Integer).Value = page;
cmd.Parameters.Add("paramName", OleDbType.VarWChar).Value = name;
cmd.Parameters.Add("paramComment", OleDbType.VarWChar).Value = comments;
cmd.Parameters.Add("paramMail", OleDbType.VarWChar).Value = mail;
con.Open();
cmd.ExecuteNonQuery();
con.Close();
|
|
|
|
|
use single quotes :
VALUES ('" + page + "','" + name + "','" + comments + "','" + mail + "')";
|
|
|
|
|
Hi,
the following is an excerpt of a program, showing the part that starts another application:
<br />
System.Diagnostics.Process process = new System.Diagnostics.Process();<br />
process.StartInfo.Arguments = args;<br />
process.StartInfo.FileName = filepath;<br />
process.Start();
Filepath directs to a program called webLCR. Later I want to check whether this application has been closed. I’m using process.HasExited . The problem is, that HasExited returns true even if the process is still running. In deed it does after the process has been started. When using another application (I tested MS Word XP) instead of webLCR and everything works fine (false when running, true when closed). Is this a known problem? Any other possibilities to check if the program is still running or not?
My System:
Windows XP Serviepack 2
Visual Studio .net 2002
Thanks
|
|
|
|
|
The question becomes what is "webLCR"? The name would suggest a web application of some kind, maybe a Java app? Is your filepath pointing to an .EXE file?
This is not a bug. The problem can show up if you're monitoring an application that launches another application that you actually see. The first application can then quit, leaving the UI application that you see running. This would result in the behavior that your seeing. If you try and monitor the installation of an .MSI, this behavior is what you'd see.
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
webLCR is a web least cost router. The filepath is pointing to an .exe file. But of course it may be that webLCR.exe launches another application and quits itself at startup. If I look at what webLCR does this seems to be quite probable. Thanks for the reply. I'm trying to get a handle on that other process now, so that I can check, whether it has exited or not. Any other (better) suggestions?
|
|
|
|
|
It works, thanks for the reply again.
|
|
|
|
|
Greetings,
This is my first post to the forum. I am a relatively new programmer and hope that my questions aren't too simple or obvious for someone at my level. I think I am getting the hang of it but am wrestling with Invoking back to the Main Thread. I have some fundamental questions that would help me understand the basics. I trust someone here will have the right answers.
From what I understand so far each Form runs in its own thread and each of its controls run on their own threads. I wish that we were in person so that you could stop me right here if I'm wrong but I will continue with my questions based on that premise which leads me to my first question.
1. When the Application.Run() method (in the main entry point for the application.) runs the Form passed to it, is there now 2 threads running? The App thread and the Form's thread? Or does the Form's thread become the MAIN THREAD?
Either way there is a Main Thread. So, when other threads are run from the main thread they need to Invoke() or BeginInvoke() back to the main thread, as they need to change variables in the app's main thread or else the change only seems to occur in the context of the thread making the changes. Now, if this is true then my next question is this:
2. Is it normal to have a large amount of EventHandlers in the main thread (main form?) for the other threads to invoke back to?
Let's say I have 40 classes that need to call back to the main thread with invoke. Is it normal to pass the main thread object into their constructor so that they can reference the main object? Something like this:
Form2 frm2 = new Form2(this);
This is how I have been doing it and it just seems messy. I mean, it just doesn't seem like I'm doing this right. If this is normal (or good coding practice) then my next question is this... and it is real basic so please don't laugh! lol
3. When you pass an object into another (or a method I would presume) does that object get copied into a new area in memory?
I know that there is a ref keyword that only sends a reference to the same memory. If this is the case why don't I see the ref keyword all over the place? It seems like it is rarely used. Even in places where it seems like it should have been used it isn't. Is there a reason for this? With that in mind my next question is this:
4. If passing my main-thread-form into each of my 40 class's constructor (as shown above) does that mean that I now have 41 main-thread-form-objects in memory? If so, wouldn't it be better to:
Form2 frm2 = new Form2(ref this);
...and use the reference to invoke off of?
I know these are fundamental concepts and I have been trying to get answers to this but none of the books I have give me the straight-dope on the practical usage. And I ask the book a question and it just sits there!
5. If passing the main-thread-form into every other class that needs to talk with it isn't the right way to do this then what is?
Let's say I have 500 classes that need to either change vars in the main class or invoke back to the main-thread-form. It seems ridicules to be passing it into the constructor like this. Especially if each one has a separate copy of the main-object.
6. Is the answer some kind of static object which contains the instance of the object? Thus avoiding all the copying and passing?
I haven't done that yet as it doesn't make sense either.
If passing the main-thread-form around like this is, indeed, the way to construct an app I would be totally cool with that and continue on my way. But it doesn't seem right and I hope you can point me in the right direction.
EB
|
|
|
|
|
From what I understand so far each Form runs in its own thread and each of its controls run on their own threads. I wish that we were in person so that you could stop me right here if I'm wrong but I will continue with my questions based on that premise which leads me to my first question.
Forms don't have threads, applications do. All controls have Window procedures which receive messages from the OS. You need (atleast) a thread to act as a message pump, to receive the messages and process them. You can create as many threads as you want. When you call Application.Run from a particular thread, that thread becomes the message pump for that form.
1. When the Application.Run() method (in the main entry point for the application.) runs the Form passed to it, is there now 2 threads running? The App thread and the Form's thread? Or does the Form's thread become the MAIN THREAD?
Application.Run starts a message loop on the current thread. So if you call Application.Run from Main(), the main thread is used as the message pumping thread. You can see that for yourself, Application.Run() blocks and doesn't return (until the app closes).
Either way there is a Main Thread. So, when other threads are run from the main thread they need to Invoke() or BeginInvoke() back to the main thread, as they need to change variables in the app's main thread or else the change only seems to occur in the context of the thread making the changes.
No, Invoke() and BeginInvoke() are needed if you are modifying the UI from a different thread. One of the basic laws of Windows is that you can modify the UI only from the thread that created it. Invoke() and BeginInvoke() are used to execute code on the thread that created the UI. It has nothing to do with normal variables. Each thread has its own stack, so local variables are not shared across threads, maybe your problem is because of this?
2. Is it normal to have a large amount of EventHandlers in the main thread (main form?) for the other threads to invoke back to?...
That's ok as long as it makes sense in that context. Again, you are passing a Form object, not a thread object.
3. When you pass an object into another (or a method I would presume) does that object get copied into a new area in memory?
I know that there is a ref keyword that only sends a reference to the same memory...
No. If it is a reference type (the Form object is), only the reference gets passed around, the whole object is not copied. It's like passing a pointer in C/C++. The ref keyword is used to achieve the effect of passing a pointer to a pointer in C/C++ (when you need to change the reference itself).
4. If passing my main-thread-form into each of my 40 class's constructor (as shown above) does that mean that I now have 41 main-thread-form-objects in memory? If so, wouldn't it be better to:
Form2 frm2 = new Form2(ref this);
...and use the reference to invoke off of?
Well, there will be only object in memory and 41 references to it. And the code you wrote won't compile, you can't pass "this" by ref as that would mean that you would be able to change "this" itself.
5. If passing the main-thread-form into every other class that needs to talk with it isn't the right way to do this then what is?
What do you do inside those 500 classes? If all they do is subscribe to events from the mainform, you can pass the mainform as part of the EventArgs.
6. Is the answer some kind of static object which contains the instance of the object?
A static object would solve the passing around of the main form.
Regards
Senthil
My Blog
|
|
|
|
|