aherrick
aherrick

Reputation: 20179

.NET Web Service Client Calls performance issue

I have an ASP.NET MVC application which is calling into a WCF Service. Below is how I am doing the call with every request.

var xml = "my xml string";
var ep = new EndpointAddress("http://myendpoint");
xml = new Proxy.ServiceClient(new NetTcpBinding(), ep).getNewXML(new Proxy.CallContext(), xml);

The problem I'm having is with the number of requests and not recycling.

See the screenshot below using Performance Monitor. I ran this test by opening the web browser on the server and just holding down enter (which each request does a form post and then tries to call the Proxy Client)

enter image description here

At this point the web browser just spins until the instances start dropping. This usually takes about 30 seconds but it is causing issues when lots of activity is performed on the server. What can I do to prevent it reaching 100%?

Upvotes: 3

Views: 2039

Answers (2)

Derek W
Derek W

Reputation: 10046

You should close your proxy as soon as you are finished using it. It is not recommended to use the using statement in the case of the disposable WCF Client Proxies since their Dispose() method may throw an exception. See here for details.

Something like this would suffice:

var client = new MyServiceClient();
try
{
    client.Open();
    client.MyServiceCall();
    client.Close();
}
catch (CommunicationException e)
{
    ...
    client.Abort();
}
catch (TimeoutException e)
{
    ...
    client.Abort();
}
catch (Exception e)
{
    ...
    client.Abort();
    throw;
}

Upvotes: 2

ZZZ
ZZZ

Reputation: 2802

The client proxy class is disposable - having the IDisposable implemented because a connection is a resource that should be disposed asap. In your codes you did not seem to dispose the proxy object after use. The common code pattern of making client calls is like this.

using (var proxy= new MyProxyClass(...))
{
   proxy.DoSomething(...);
}

Resource leaks on client side can cause severe performance problems on both client side and server side. Since your MVC application (Web service broker) is a client to the WCF service, the damage to overall performance is escalating.

Upvotes: 2

Related Questions