Reputation: 36540
I have deployed the same self-host windows service to 2 different servers. (One primary, one backup) Basically, this service provides HTTP protocol access (e.g. http://machine1:60001/getdata/123).
I have set the configuration for consumers, to connect the primary one all the time (http://machine1:60001), but this requires some down time whenever we deploy this service.
As this service should be available all the time, is there any easy way to set the load balance, or fail-over for this windows service?
By the way, for the self-host service, it has an interface: http://machine1:60001/amialive to decide whether the service is available. And I want to use this interface to decide whether it is OK.
Upvotes: 0
Views: 588
Reputation: 36540
After a few days investigation, I found a WCF built-in feature: WCF routing system. (System.ServiceModel.Routing.IRequestReplyRouter)
Basically, it could route all WCF requests from end client to destination service. Actually, it works both as a client and a WCF service. End client connects to this (As a WCF service), while at the same time, this connects to destination services (As a client). You can get the information through the app.config which covers both client config as well as service config.
You can find the simple implementation here in msdn:
https://msdn.microsoft.com/en-us/library/ee667246(v=vs.110).aspx
Upvotes: 1
Reputation: 127563
Other than the few issues you need to be aware of that are outlined in the MSDN article on Load Balancing WCF (for example you should disable KeepAlive if you plan on using load balancing and not just failover setups), you can use any generic HTTP load banlancing techneque.
How you set up HTTP load balancing all depends on your deployment and likely could take up a entire question itself, but the quick version is you have some piece of hardware, software, or 3rd party service that intercepts all requests for http://machine1:60001 which then directs the connection on to the actual physical machine that will be hosting the request.
Upvotes: 1