.NET Web Service client causing performance issues

I have an ASP.NET MVC application that calls a WCF service. Below is how I make the call with each 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 am having is related to the number of requests, not the processing.

See screenshot below using Performance Monitor. I tested this test by opening a web browser on the server and just hitting the enter button (each request sends a form post and then tries to invoke the proxy client).

enter image description here

At this point, the web browser just spins around until the instances start dropping. This usually takes about 30 seconds, but it causes problems when there are many operations on the server. What can I do to prevent it from reaching 100%?

+3


source to share


2 answers


The client proxy class is disposable - the IDisposable implementation is implemented because the connection is a resource that should be disposed of as soon as possible. In your codes, you don't seem to be using the proxy object after use. The general code for creating client calls is as follows.

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

      



Client-side resource leaks can cause severe performance problems on both the client and the server. Since your MVC (Web Service Broker) application is a client of a WCF service, the overall performance penalty is increased.

+2


source


You must close your proxy as soon as you are finished using it. It is not recommended to use the operator using

in the case of one-time WCF proxies because their method Dispose()

can throw an exception. See here for details .

Something like this would be sufficient:



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;
}

      

+2


source







All Articles