![]() |
![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() |
| Welcome to Windows Vista Forums. Our forum is dedicated to helping you find solutions with any problems, errors or issues you are experiencing with Windows Vista. The Vista forum also covers news and updates and has an extensive Windows Vista tutorial section that covers a wide range of tips and tricks. |
| |||||||
| |
| | #1 (permalink) |
| | ServiceHost in a Form Hi there, I've successfully implemented a client and a server running from the static Main method of a Windows Forms application. For example: [STAThread] static void Main() { MyServer server = new MyServer(); MyClient client = new MyClient("http://localhost/myServer"); Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); Application.Run(new Form1()); } The MyClient contructors contains a method call to the server, and receives a response from the server. Everything works great. BUT, if I wish to perform the same server-client code sample within the Form1 instance (e.g. after a button click etc'), I get a 'timed out' exception. My guess is that it is probably a threading issue, and that the Form's mainthread is blocking the ServiceHost of the server. If this is correct, then I must say that I thought I read somewhere that the ServiceHost is always running on a different thread. So, any ideas as to what the problem is and how to solve it? |
My System Specs![]() |
| | #2 (permalink) |
| | Re: ServiceHost in a Form Eventually I ended up in performing the hosting and client connection on different threads, and it worked-around the problem. However, I'll be happy if someone posts a solution to this. Thanks. |
My System Specs![]() |
| | #3 (permalink) |
| | Re: ServiceHost in a Form Yes , that exactly , the problem , service need to listen for client(s) request, but your client sit on the same thread. BTW why you need client and service in the same app , that against tenet 1 of web services. If you have service/client pair talk to different service/client pair that's OK , but not in this case Arkady "ewolfman" <ewolfman@yahoo.com> wrote in message news:1151299765.256777.310920@m73g2000cwd.googlegroups.com... > Eventually I ended up in performing the hosting and client connection > on different threads, and it worked-around the problem. > > However, I'll be happy if someone posts a solution to this. > > Thanks. > |
My System Specs![]() |
| | #4 (permalink) |
| | Re: ServiceHost in a Form They don't have to exist in the same app - it occurs between different apps too. I just wanted to demonstrate the problem. According to your answer, a WinForm application can only host outside the main thread - did I understand correctly? |
My System Specs![]() |
| | #5 (permalink) |
| | Re: ServiceHost in a Form As I mentioned, the blocking occurs on 2 different applications (i.e. client and server running in different applications). |
My System Specs![]() |
| | #6 (permalink) |
| | Re: ServiceHost in a Form No, I meant that you have client and service on the same thread. You have to separate client and service , those have to be two different applications Arkady "ewolfman" <ewolfman@yahoo.com> wrote in message news:1151314200.399066.198430@u72g2000cwu.googlegroups.com... > They don't have to exist in the same app - it occurs between different > apps too. I just wanted to demonstrate the problem. > > According to your answer, a WinForm application can only host outside > the main thread - did I understand correctly? > |
My System Specs![]() |
| | #7 (permalink) |
| | Re: ServiceHost in a Form I see now , in this case form and host service run on the same thread Arkady "ewolfman" <ewolfman@yahoo.com> wrote in message news:1151331282.931319.305360@i40g2000cwc.googlegroups.com... > As I mentioned, the blocking occurs on 2 different applications (i.e. > client and server running in different applications). > |
My System Specs![]() |
| | #8 (permalink) |
| | Re: ServiceHost in a Form As I initially mentioned, this is what I gather the problem to be. Do we have a method of hosting on a different thread? I thought I read somewhere that it is automatically handled, but I guess it isn't so. So my question is, what is the correct way of hosting in a WinForms application ? |
My System Specs![]() |
| | #9 (permalink) |
| | Re: ServiceHost in a Form Just as you did : create the thread and host service there, btw if you mean service behavior concurrencymode( multiple ) that not work with many clients but only one after another ( when previous client close connection ) even in Beta 2 ![]() Arkady "ewolfman" <ewolfman@yahoo.com> wrote in message news:1151404338.477824.15860@p79g2000cwp.googlegroups.com... > As I initially mentioned, this is what I gather the problem to be. Do > we have a method of hosting on a different thread? I thought I read > somewhere that it is automatically handled, but I guess it isn't so. > > So my question is, what is the correct way of hosting in a WinForms > application ? > |
My System Specs![]() |
| Thread Tools | |
| |
Similar Threads | ||||
| Thread | Forum | |||
| Form Problem | PowerShell | |||