locked
Multiple Request Handle in Soap Based WebService in C# RRS feed

  • Question

  • User-1637592233 posted

    I have a web service(.asmx) which was developed 2 Years ago. Initialy it worked fine, but now as the client requests are increasing there is a problem handling multiple concurrent requests. The requests are as simple as shown below.

     <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:app="https://external.nationaltaxcredit.com/ws/ApplicantService.asmx">
           <soapenv:Header>
              <app:Authentication>
                 <!--Optional:-->
                 <app:PartnerKey>*****</app:PartnerKey>
                 <!--Optional:-->
                 <app:AuthenticationKey>*****</app:AuthenticationKey>
              </app:Authentication>
           </soapenv:Header>
           <soapenv:Body>
              <app:GetForms>
                 <!--Optional:-->
                 <app:applicantId>****</app:applicantId>
              </app:GetForms>
           </soapenv:Body>
        </soapenv:Envelope>

    Nowadays, with the increase in number of requests, often concurrently,following errors occur:

    1. Out.Of.Memory Exception
    2. Time Out Exception
    3. DeadLock error

    The hardware resource available to us is supposed to handle the multiple requests but somehow these resources are not available to handle even two requests at a time and often in such case, the system goes out of Memory or Time Out Exception occurs.

    I have gone through this article too, but I could not figure out the possible solution that I am looking for.

    https://blogs.msdn.microsoft.com/ericlippert/2009/06/08/out-of-memory-does-not-refer-to-physical-memory/

    The Code for above xml request contains these operation.

    [WebMethod()]
    public StatusResponse GetStatus(string applicantId)
    {
        var info = GetPartnerInfo();
    
        if (IsAuthenticated(info)) //CheckAuthentication()
        {
            int userId = statusService.ValidateAppId(applicantId, info.PartnerId);
            statusResponse = statusService.GetStatusOfApplicant(userId);
            return statusResponse;
        }
    }
    private Partner GetPartnerInfo()
    {
        IPartnerService partnerSrv = ObjectFactory.GetInstance<IPartnerService>();
    
        var info = partnerSrv.GetInfo(authentication.PartnerKey, authentication.AuthenticationKey);
    
        return info;
    }
    private bool IsAuthenticated(Partner pa)
    {
        if (pa == null)
        {
            return false;
        }
        else
        {
            if (pa.PartnerId == 3)
                return true;
            else
                return false;
        }
    }

    I tried by disposing the Object after finally {}, when the request is success for any successful request, but it did not work.

    Please suggest me for any possible work around for this and please let me know if I should change my approach from the outset to solve this problem.



    Thursday, October 20, 2016 1:38 PM

All replies

  • User765422875 posted

    Do you have the service installed on multiple servers behind a load balancer? If not, do you have a web garden set up?

    Thursday, October 20, 2016 2:51 PM
  • User-1637592233 posted

    No, the service is only on Single server and i have not set up Web garden. 

    Thursday, October 20, 2016 3:15 PM
  • User765422875 posted

    If setting up multiple servers behind a load balancer is out of the question, then you can set up a web garden and see if that helps (its straightforward to do). Web Garden in IIS terms is just using more worker processes.

    For IIS 7, Right Click on Application Pool > Go To Advance Settings > In Process Model section, you will have “Maximum Worker Processes”. You can change it more than 1 to make it as a web garden.

    You also mentioned deadlocks and timeouts. Deadlocks occur when two or more tasks permanently block each other by each task having a lock on a resource.

    I'm assuming there is SQL involved behind the scenes. Have you troubleshooted the queries that are running and causing deadlocks?

    Thursday, October 20, 2016 3:29 PM
  • User-1637592233 posted

    Isn't their any option with the code base ? 

    Thursday, October 20, 2016 3:42 PM
  • User765422875 posted

    There can be options with code, but I don't know the code well enough to give a completely detailed answer. You mentioned deadlocks and timeouts which I assume refer to your underlying SQL code. I suggest you troubleshoot the source of the timeouts and deadlocks in your SQL code.

    Thursday, October 20, 2016 3:43 PM
  • User-1637592233 posted

    For a normal request that is two request with a interval of 4-5 seconds is always success, their will not be any problem. But, if their is the request with less than 3-4sec their is always a deadlocks and the error is 

    ?xml version="1.0" encoding="utf-8"?>     Failed  Transaction (Process ID 62) was deadlocked on lock | communication buffer resources with another process and has been chosen as the deadlock victim. Rerun the transaction.



    Thursday, October 20, 2016 3:49 PM
  • User765422875 posted

    Again, I'm assuming you have a database behind this web service. The SQL behind your code may be what  is causing your deadlocks and timeouts. I would profile the sql that is being run on the server to determine the root cause of the issue.

    Thursday, October 20, 2016 5:12 PM