Click here to Skip to main content
13,148,427 members (61,595 online)
Rate this:
Please Sign up or sign in to vote.

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"
          <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" />

<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?

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.
Posted 12-Mar-13 18:56pm

1 solution

Rate this: bad
Please Sign up or sign in to vote.

Solution 1

Some steps you can go to analyse your problem:

1) Implement a simple test method in your WCF service, e.g.

public in TestMethod(int data)
    return (data + 1);

and look how long it takes to call it from your client.

If it is fast enough, your next steps would be to see if, EF or your returning list is the problem.

2) call the method, which returns the list/array but without using the EF.
So just create a list with some dummy data and return it. Try different amounts of items, e.g. 1, 2, 5, 10, 100,... Look how long it takes.

Your point about opening/closing the DB connection in each function call:
I would probably open/initialize the DB context at the first call and then leave it open. I would register for the InstanceContext.Closed Event to close the db context. You could try to open the DB context in the InstanceContext.Opend event, too.

Lust but not least, I don't think, that the network is the problem, when you are in your local network.

Hope it helps
DeepsMann 14-Mar-13 0:47am
Hi Andy,
Thanks for reply.
I tried using a test method. It doesn't take that much time. Now I figured out that the problem was with EF. The views generated were not working.

I was using Code first approach. And I generated views for performance improvement. But there was no change. So, I tried switching to Database first and then i created views. And the time reduced to 10 seconds from 40 seconds.

Then, I tried your 3rd point, and it helped. The time now reduced to 5 seconds. Thanks
Andy411 14-Mar-13 3:29am
You're welcome :-)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy |
Web03 | 2.8.170924.2 | Last Updated 13 Mar 2013
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100