Thursday, 19 September 2013

Changing service reference endpoint at runtime, sometimes the wrong endpoint is used

Changing service reference endpoint at runtime, sometimes the wrong
endpoint is used

I have a WCF service that in turn has a service reference to some other
SOAP endpoint. This endpoint has an identical copy at another address with
the same metadata but different data. When a request comes in to my
service, it specifies which of the two identical endpoints that I consume
it wants data from. So, I have something like this:
using (var client = new ServiceClient())
{
client.Endpoint.Address = new System.ServiceModel.EndpointAddress(url);
//do some work, pull some data, bake some muffins
}
This sometimes doesn't work when I have two requests coming in very close
together with different urls. The second request ends up going out to the
same endpoint as the first one. I understand that once the channel is open
I can't change the endpoint, but I thought the client would only be used
once and then disposed. Is there some optimization going on where the same
proxy is being re-used for multiple requests? What's a good approach to
problems like this?

No comments:

Post a Comment