Windows Vista Forums
Vista Forums Home Join Vista Forums Windows 7 Forum Vista Tutorials Tags
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.

Go Back   Vista Forums > Misc Newsgroups > Indigo

Vista - ServiceHost in a Form

 
 
Old 06-25-2006   #1 (permalink)
ewolfman


 
 

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 SpecsSystem Spec
Old 06-26-2006   #2 (permalink)
ewolfman


 
 

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 SpecsSystem Spec
Old 06-26-2006   #3 (permalink)
Arkady Frenkel


 
 

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 SpecsSystem Spec
Old 06-26-2006   #4 (permalink)
ewolfman


 
 

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 SpecsSystem Spec
Old 06-26-2006   #5 (permalink)
ewolfman


 
 

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 SpecsSystem Spec
Old 06-26-2006   #6 (permalink)
Arkady Frenkel


 
 

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 SpecsSystem Spec
Old 06-27-2006   #7 (permalink)
Arkady Frenkel


 
 

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 SpecsSystem Spec
Old 06-27-2006   #8 (permalink)
ewolfman


 
 

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 SpecsSystem Spec
Old 06-28-2006   #9 (permalink)
Arkady Frenkel


 
 

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 SpecsSystem Spec
 

Thread Tools


Similar Threads
Thread Forum
Form Problem PowerShell


Vista Forums is an independent web site and has not been authorized,
sponsored, or otherwise approved by Microsoft Corporation.
"Windows Vista", the Start Orb, and related materials are trademarks of Microsoft Corp.
© Designer Media Ltd

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46