|
-
Oct 8th, 2009, 02:00 AM
#1
Starting and Stopping a WCF Service
Hi,
I have a WCF service, which I can open and close by doing:
Code:
Dim myService As MyServicehost = New MyServiceHost()
myService.Open()
myService.Close()
the issue is that while the MyServicehost is operational, ie up and running, I need to destroy it, and create a new service host:
Code:
Dim myService As MyServiceHost = New MyServiceHost()
myService.Open()
Dim newService As MyServiceHost = New MyServiceHost()
myService.Close()
newService.Open()
The problem with this is I have "downtime" of the service in between myService.Close() and newService.Open(). if anyone tries to connect while this is happening it fails.
how can I make the "downtime" as small as possibel?
Make sense? 
Woka
-
Oct 8th, 2009, 03:03 AM
#2
Re: Starting and Stopping a WCF Service
You could try this:
Code:
Dim myService As MyServiceHost = New MyServiceHost()
myService.Open()
Dim newService As MyServiceHost = New MyServiceHost()
newService.Open()
myService.Close()
But I haven't validated to check if this works, it could fail because the 2 servicehosts are both active. Why do you need the recreate the service anyway?
-
Oct 8th, 2009, 03:40 AM
#3
Re: Starting and Stopping a WCF Service
You cannot open 2 services at the same time.
You get an error saying that 2 listeners cannot listen to the same port.
So I must stop one service 1st...or delete it's endpoint listener.
I need to do this because I need to refresh cache in the service.
Woka
-
Oct 8th, 2009, 04:02 AM
#4
Re: Starting and Stopping a WCF Service
In that case the simplest thing to do, I think, would be to write a method to clear cache. This can, of course, only work if you handle the caching yourself.
-
Oct 8th, 2009, 05:06 AM
#5
Re: Starting and Stopping a WCF Service
lol.
I knew you were gonna say that 
It's not possible do clear the "cache" as the cache is assemblies loaded into a new AppDomain, which needs to be destroyed and thus I must create a whole new servicehost in a new AppDomain.
Woka
-
Oct 8th, 2009, 05:28 AM
#6
Re: Starting and Stopping a WCF Service
IF it is possible you could host the service in the IIS so you can recycle the "worker processes". The services is always available, but will get restarted.
But only if you can host in the IIS
-
Oct 8th, 2009, 05:47 AM
#7
Re: Starting and Stopping a WCF Service
Hmmm not sure I want to host in IIS tbh, windows service all the way.
I just need to make sure the "downtime" is as small as possible between .Close() and the new .Open().
Woka
-
Oct 8th, 2009, 06:16 AM
#8
Re: Starting and Stopping a WCF Service
Maybe the best to do is to create the "second" servicehost, but without endpoint configuration --> stop the first servicehost--> add the endpoint configuration, that should not take more than a few ms...
-
Oct 8th, 2009, 07:20 AM
#9
Re: Starting and Stopping a WCF Service
Yea, that sounds similar to what I've been trying..but not sure how
-
Oct 8th, 2009, 08:55 AM
#10
Re: Starting and Stopping a WCF Service
I don't know the exact code you use to create the service host. If you do this (C# but you should understand):
Code:
Uri baseAddress = new Uri("https://localhost");
ServiceHost myService = new ServiceHost(typeof(myserviceTypel), baseAddress);
you create the service object but it doesn't listen to request until you do:
Code:
binding.Name = "myBinding";
binding.HostNameComparisonMode = HostNameComparisonMode.WeakWildcard;
binding.Security.Mode = BasicHttpSecurityMode.TransportWithMessageCredential;
Uri address = new Uri("myServiceAddres" , UriKind.RelativeOrAbsolute);
myService .AddServiceEndpoint(typeof(myServicePort), binding, address);
-
Oct 8th, 2009, 09:01 AM
#11
Re: Starting and Stopping a WCF Service
By the way, depending on the type of connection, it is only by default that you can't have multiple listeners on a single port. I ran into the same issue when I wanted multiple processes to receive incoming UDP messages. The workaround was easy:
http://www.vbforums.com/showthread.p...&highlight=UDP
However, this may not be relevant to you. I have worked with WCF only a little, but you can get access to underlying objects, and maybe you can effect the same solution that I did (thanks to Atheist, I believe).
My usual boring signature: Nothing
 
-
Oct 8th, 2009, 09:06 AM
#12
Re: Starting and Stopping a WCF Service
hmmm...I tried similar coding to that the other day, but couldn't get it to work 
A few ms downtime is absolutely perfect! 
I will play around with this approach more this evening.
Thanks
-
Oct 8th, 2009, 09:17 AM
#13
Re: Starting and Stopping a WCF Service
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|