Windows Vista Forums
Vista Forums Home Join Vista Forums Donate Vista Tutorials Tags

Welcome to Vista Forums we are your forum to discuss Windows Vista x64 and x86 systems. Whether you need help or just want to post an idea you have on Vista, this is the forum for you.
Register at Vista forums...the world biggest Windows Vista resource Join Vista Forums Now

Go Back   Vista Forums > Microsoft Technical Newsgroups > Indigo

ServiceHost in a Form

 
 
Thread Tools Display Modes
Old 06-25-2006   #1 (permalink)
ewolfman
Guest


 

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?

Old 06-26-2006   #2 (permalink)
ewolfman
Guest


 

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.

Old 06-26-2006   #3 (permalink)
Arkady Frenkel
Guest


 

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.
>



Old 06-26-2006   #4 (permalink)
ewolfman
Guest


 

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?

Old 06-26-2006   #5 (permalink)
ewolfman
Guest


 

Re: ServiceHost in a Form

As I mentioned, the blocking occurs on 2 different applications (i.e.
client and server running in different applications).

Old 06-26-2006   #6 (permalink)
Arkady Frenkel
Guest


 

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?
>



Old 06-27-2006   #7 (permalink)
Arkady Frenkel
Guest


 

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).
>



Old 06-27-2006   #8 (permalink)
ewolfman
Guest


 

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 ?

Old 06-28-2006   #9 (permalink)
Arkady Frenkel
Guest


 

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 ?
>



 

Thread Tools
Display Modes


Similar Threads
Thread Thread Starter Forum Replies Last Post
form problems PowerShell 5 09-26-2007 01:24 PM








Vistax64.com 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 2005-2008

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 47 48 49 50