Note that there are some explanatory texts on larger screens.

plurals
  1. POChanging service reference endpoint at runtime, sometimes the wrong endpoint is used
    text
    copied!<p>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:</p> <pre><code> using (var client = new ServiceClient()) { client.Endpoint.Address = new System.ServiceModel.EndpointAddress(url); //do some work, pull some data, bake some muffins } </code></pre> <p>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?</p> <p><strong>EDIT:</strong> More detail:</p> <p>The snippet is part of a method (let's call it foo()) that's exposed to consumers of my RESTful service. It is not static. The endpoint url is a local string that's supplied as part of the URI.</p> <pre><code>[OperationContract] [WebInvoke(Method = "GET", ResponseFormat = WebMessageFormat.Json, UriTemplate = "getStuff?url={url}")] string foo(string url); public string foo(string url) { using (var client = new ServiceClient()) { client.Endpoint.Address = new System.ServiceModel.EndpointAddress(url); //do some work, pull some data, bake some muffins return "SO rocks!"; } } </code></pre> <p>I haven't set up anything explicit for concurrency control. I understand the theory behind it but lack technical experience, so any hand-holding would be very appreciated.</p> <p><strong>Also!</strong> There was a semi-valid reason to change the endpoint address rather than specify it in the proxy constructor. However, for testing purposes I just tried specifying in the constructor and it appears to be working perfectly (thanks JMeter!). With a little bit of work I could restructure the real code to work that way, but I would still be very grateful for an explanation. Learning is important.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload