none
Connection to WCF Service takes long time RRS feed

  • Question

  • Hello,

    I have a WCF service hosted on IIS 7.5 on my server. I have used Entity framework 5.0 in my service.

    When I call that service from my local system by adding service reference and creating client in a site, it takes approx 40 seconds to get the response. I tried calling the same service which is on my local and here it takes only 3-4 seconds. 

    After adding reference to the service which is on server to the site which is on local system, the binding and endpoint added in web config looks like:

    <binding name="WSHttpBinding_IMyWCFService" closeTimeout="00:01:00"
              openTimeout="00:01:00" receiveTimeout="00:50:00" sendTimeout="00:01:00"
              bypassProxyOnLocal="false" transactionFlow="false" hostNameComparisonMode="StrongWildcard"
              maxBufferPoolSize="524288" maxReceivedMessageSize="2147483647"
              messageEncoding="Text" textEncoding="utf-8" useDefaultWebProxy="true"
              allowCookies="false">
              <readerQuotas maxDepth="32" maxStringContentLength="2147483647"
                maxArrayLength="16384" maxBytesPerRead="4096" maxNameTableCharCount="16384" />
              <reliableSession ordered="true" inactivityTimeout="00:10:00"
                enabled="false" />
              <security mode="Transport">
                <transport clientCredentialType="None" proxyCredentialType="None"
                  realm="" />
                <message clientCredentialType="Windows" negotiateServiceCredential="true" />
              </security>
            </binding>
    <endpoint address="https://<url>/MyWCFService.svc/soap"
            binding="wsHttpBinding" bindingConfiguration="WSHttpBinding_IMyWCFService"
            contract="MerchantService.IMyWCFService" name="WSHttpBinding_IMyWCFService" />

    first I thought that it is a issue of Entity framework. But then i checked the execution time of the method using Entity framework profiler. Its hardly taking 1 second.

    also when i call the service, it requires to add a header, which I am adding. 

    So, where it is taking that 40 seconds time. And its not slow startup or taking time only for first time. It takes this much time always.

    Is network speed can be a cause to this delay. If yes, up to what extent?

    Edit:

    The service returns a list List<MyClass>. Could it be a problem, that we should not return Lists. What can be the alternative?

    Also, does Entity framework establishes connection to DB every time a request comes and if the Database connection is taking time. Can it be possible?

    Please help.

    Thanks


    Deepti


    • Edited by deepti_M Tuesday, March 12, 2013 9:29 AM
    Monday, March 11, 2013 1:09 PM

Answers

All replies

  • Are you getting back a ton of data from the database that you are sending across the network?  Even with a fast pull from the server's local database if it returns a lot of data that needs to be sent across the network it can still be very slow depending on your network infrastructure.

    Was your local run of the server on your dev machine using the same database contents as your server database such that your call to it would yeild the same data to be returned to your client as when you tested against the remote server?

    If you run the client on your server (eliminating the network in a different way) does the timing drop down also?  If it does that would be a pretty good indicator that the network is the bottle-neck.

    Monday, March 11, 2013 5:53 PM
  • Enable tracing and view the trace log using WCFTraceViewer to diagnose the problem. 

    WCF Trace viewer can be found at C:\Program Files\Microsoft SDKs\Windows\v6.0\Bin\SvcTraceViewer.exe

    Going through the service trace can reveal the reason behind this behavior.


    Apriori algorithm [association rule]

    Monday, March 11, 2013 6:52 PM
  • Thanks for reply BotHead,

    The service returns a list containing 84 records. Yes the database records on local and remote server are same. But the time its taking is to much comparing the amount of data its returning. Isn't it?

    And I tried accessing the service from a client on server itself. The time is just the same : 40 seconds.

    Its doesn't drops. 

    Also I tried the local service with the database connection string of Remote server database. It takes only 4-5 seconds.


    Deepti


    • Edited by deepti_M Tuesday, March 12, 2013 5:52 AM
    Tuesday, March 12, 2013 4:51 AM
  • Hello Sukumar,

    Thanks for reply. 

    I didn't found any folder as Microsoft SDKs in Program files on remote server. Though the tracing is enabled in Gibraltar Software. I will try seeing in that if it shows any reason.


    Deepti

    Tuesday, March 12, 2013 5:04 AM
  • Hello Sukumar,

    I have enabled the tracing in service at remote server. And viewed it in SvcTraceViewer. The image is below:

    The area in red rectangle is the latest activities. And the red oval part shows the details for the selected activity in red rectangle. Please look at the time difference between "Activity Boundary suspend" and "From: Execute...". Its 37 seconds. What is this Activity Boundary? Where the time is taken.

    Please comment.

    Thanks.


    Deepti

    Tuesday, March 12, 2013 1:51 PM
  •  

    Dear Deepti

    make sure your all file stored in specific location like app_data, app_bin etc so that you will get faster webpage in ur application.

    just try like this way.


    Thanks . Rajesh Kumar email-Id :rkumar1904@hotmail.com

    Tuesday, March 12, 2013 2:15 PM
  • What level of trace logging did you have setup?  You may be able to configure that to give you some more information that is occurring (i.e. using All or Verbose).

    The documentation on why an activity would suspend is as follows:
    (http://msdn.microsoft.com/en-us/library/aa738618.aspx)
    Suspend: Indicates suspension of processing of an activity. A “Suspend” trace contains an existing activity ID whose processing is expected to resume at a later time. No traces are emitted with this ID between the Suspend and Resume events from the current trace source. Examples include pausing an activity when calling into an external library function, or when waiting on a resource such as an I/O completion port.

    If you look at your trace log in the graph interface you may be able to see exactly what is going on (i.e. a different activity is starting while the one you are looking at has suspended).  Here is an example of what that looks like:
    http://msdn.microsoft.com/en-us/library/aa751795.aspx

    Wednesday, March 13, 2013 5:31 PM
  • Follow up question.  When you tested locally how did you host the service?  IIS, the VS service hosting platform, self-hosted, etc?
    Wednesday, March 13, 2013 7:00 PM
  • The service is hosted in IIS. Also I figured out that the problem was with EF.

    It was taking too much time in establishing connection with DB and view generation. Because I was using code first approach and generated views and still it was taking 40 seconds. But then I switched to Database First approach and generated views and now its taking 10 seconds. then I tried opening DB connection on WCF service startup and the time again reduced to 5 seconds.

    What I didn't understand is that is EF gives this much slow performance for a DB having only 17 tables, not too much inheritance, no complexities and a table containing maximum of 90 rows. Then how anyone can be sure that the performance will not degrade further when the services will get Live and there will be thousands of records.

    Thanks


    Deepti

    Thursday, March 14, 2013 5:03 AM
  • Use SQL profiler to know the reason behind the SQL performance.


    Apriori algorithm [association rule]

    Thursday, March 14, 2013 5:33 AM