连接到WCF服务需要很长时间 [英] Connection to WCF Service takes long time

查看:78
本文介绍了连接到WCF服务需要很长时间的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好,



我的服务器上的IIS 7.5上托管了WCF服务。我在我的服务中使用了Entity framework 5.0。



当我通过添加服务引用并在站点中创建客户端从本地系统调用该服务时,大约需要40个获得响应的秒数。我尝试在本地调用相同的服务,这里只需3-4秒。



将服务器上的服务引用添加到本地系统上的站点后,web config中添加的绑定和端点如下所示:



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





首先我认为这是Entity框架的问题。但后来我使用Entity framework profiler检查了该方法的执行时间。它几乎不需要1秒钟。



当我打电话给服务时,它需要添加一个标题,我正在添加。



所以,这需要40秒的时间。它不是慢启动或只是第一次花时间。总是花费这么多时间。



网络速度是导致这种延迟的原因。如果是,可以达到什么程度?



该服务返回列表List< myclass>。这可能是一个问题,我们不应该返回列表。还有什么可以替代?



此外,每当请求到来以及数据库连接需要时间时,Entity框架是否建立与DB的连接。可以吗?



请帮忙。

谢谢



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.
Thanks

推荐答案

您可以采取一些步骤来分析您的问题:



1)在您的WCF服务中实施一个简单的测试方法,例如



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





并查看从客户端拨打电话需要多长时间。



如果它足够快,你接下来的步骤就是看看,EF或你的返回列表是否有问题。



所以:

2)调用方法,该方法返回列表/数组但不使用EF。

所以只需创建一个带有一些虚拟数据的列表并返回它。尝试不同数量的商品,例如1,2,5,10,100,...看看需要多长时间。



3)

关于开放的意见/在每个函数调用中关闭数据库连接:

我可能会在第一次调用时打开/初始化数据库上下文,然后将其保持打开状态。我会注册InstanceContext.Closed事件来关闭db上下文。您也可以尝试在InstanceContext.Opend事件中打开数据库上下文。





欲望但并非最不重要,我不喜欢当你在本地网络时,认为网络是问题。



希望它有所帮助

Andy



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.

So:
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.

3)
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
Andy


这篇关于连接到WCF服务需要很长时间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆