开发者

Reassign a client's endpoint at runtime

开发者 https://www.devze.com 2023-03-14 11:43 出处:网络
I have C# application that runs in the background. The execution of this application can ta开发者_开发知识库ke from 1 to 10 minutes and it\'s communicating to a WCF service calling multiple web method

I have C# application that runs in the background. The execution of this application can ta开发者_开发知识库ke from 1 to 10 minutes and it's communicating to a WCF service calling multiple web methods from the start until the end of its execution.

To avoid creating/closing too many proxy objects, I've got one proxy object for the duration of the process. I have a couple of server boxes with IIS configured where a copy of the WCF service sits on and I want to use both boxes to spread out the load. For lack of an expensive load balancing solution, I want to change the endpoint address of the proxy on-the-fly to communicate with a different server box per method call.

I've tried this before the first method call:

client.Endpoint.Address = new EndpointAddress("http://box1.wcfserviceaddress.com/MyService.svc");

changing this further down the line won't have any effect and the box the client connected to first keeps receiving the method calls. Also, changing the service instance management from session to per-call doesn't make any difference.

Can this be done or do I need to create a client per method call?

Regards, F.


The proxy is derived from ClientBase which implements ICommunicationObject. All classes derived from CommunicationObject or implementing ICommunicationObject shares the same behaviour - they can be configured only in Created state. Once communication object moves from Created state the configuration cannot be changed and because of that setting address after you use the proxy for the first time (it changes state to Opened) doesn't have any effect. The only way to get the proxy with a new address is creating a new one.


Once a client is created and opened, I'm 99% sure (without double-checking to be 100%) that you can't change any of it's ABCs. You're going to have to done proxy per server.

0

精彩评论

暂无评论...
验证码 换一张
取 消