It is quite common to have a few service environments, for example one for testing and one for production. One way to switch a Wcf client from one environment to another is by changing the address in app.config:
However sometime we need to dynamically change the address from code due to some logic.
The naive approach would be to do something like this:
The reason this is naive is that app.config may contain additional information on the endpoint, namely its identity and headers:
when we create the proxy with a different endpoint in the constructor we override the identity information. This may result in this error:
The solution
Create the proxy normally. Then separately assign the new endpoint address keeping the identity and header values:
2 comments:
Another great tip :)
I was exactly looking for the same.
Thanks a ton.
You saved my time.
Regards,
Praveen
Post a Comment