简体   繁体   English

操作已超时WCF Rest

[英]The operation has timed out WCF Rest

I'm getting the following exception The operation has timed out when calling my WCF REST service. 我收到以下异常调用WCF REST服务时, The operation has timed out

I basically have a WCF Web Service project and a web site which references the compiled WCF assembly. 我基本上有一个WCF Web服务项目和一个引用已编译的WCF程序集的网站。 The web service works a charm, so my problem is not down to having an incorrect binding, endpoint or service definition in my web.config. Web服务具有魅力,因此我的问题不仅仅在于web.config中的绑定,端点或服务定义不正确。

The problem only occurs if I try to insert a large amount of data. 仅当我尝试插入大量数据时,才会出现此问题。

The web.config contains the following info: web.config包含以下信息:

<system.web>
  <compilation debug="true" targetFramework="4.0"/>
  <httpRuntime enable="true" executionTimeout="100000"
   maxRequestLength="2147483647"/>
</system.web>

<bindings>
  <webHttpBinding>
    <binding maxReceivedMessageSize="2147483647" 
             maxBufferSize="2147483647" 
             receiveTimeout="00:10:00" 
             sendTimeout="00:10:00">
      <readerQuotas maxStringContentLength="2147483647"/>
    </binding>
  </webHttpBinding>
</bindings>

My WCF web service is not referenced in the the project (windows service) as I'm using a wrapper (sdk) which takes care of making all the relevant http request and convert object to json and vice versa. 在项目(Windows服务)中未引用我的WCF Web服务,因为我正在使用包装程序(sdk),该包装程序负责进行所有相关的http请求并将对象转换为json,反之亦然。 All http request are made via the WebClient which is called the sdk. 所有http请求都是通过称为sdk的WebClient发出的。 In this instance: 在这种情况下:

byte[] returnBuffer = await client.UploadDataTaskAsync(uriString, 
"POST", requestBuffer);

While this is happening on a live site (Yikes!!), I can easily reproduce the problem by putting a breakpoint in my web service and letting it hang for 90 seconds or so, then if I try to continue stepping through, the specific error is generated and while it's attempting to continue to run the remaining of the code within the function, the exception is returned back to the client. 虽然这是在实时站点上发生的,但是我可以通过在Web服务中放置一个断点并将其挂起90秒钟左右来轻松重现该问题,然后,如果我尝试继续逐步解决该特定错误,生成并尝试继续运行该函数中的其余代码时,该异常将返回给客户端。

I've been googling this problem for hours now but I'm not getting anywhere with this. 我已经搜索这个问题了好几个小时了,但是我对此一无所知。 My web service still times out the default 90 seconds. 我的Web服务仍然超时默认的90秒。

Another thing I'm wondering about. 我想知道的另一件事。 I've been reading a lot of various article saying mentioning that the client app, in my case my windows service should have binding, endpoint, etc... information in the app.config. 我读过很多不同的文章,提到客户端应用程序,在我的情况下,我的Windows服务应在app.config中包含绑定,端点等信息。 I have none, nor have I ever needed one up to now. 我什么都没有,到目前为止也不需要。 Should I look into this?? 我应该看看这个吗? It really does appear that the timeout is happening on the web service rather than the client end. 确实确实是在Web服务而不是客户端上发生了超时。

Any ideas? 有任何想法吗?

Thanks. 谢谢。

UPDATE: 更新:

I've added additional info about my web.config (ie service & behaviour definitions): 我添加了有关web.config的其他信息(即服务和行为定义):

<services>
  <service name="MyCompany.Web.Services.WebDataService" 
                 behaviorConfiguration="WebDataServiceBehaviour">
    <endpoint address="" binding="webHttpBinding" 
              contract="MyCompany.Web.Services.IWebDataService" 
              behaviorConfiguration="webBehaviour">
    </endpoint>
  </service>
</services>

<behaviors>
  <serviceBehaviors>
    <behavior name="WebDataServiceBehaviour">
      <serviceMetadata httpGetEnabled="true" httpsGetEnabled="true"/>
      <serviceDebug includeExceptionDetailInFaults="true"/>
    </behavior>
  </serviceBehaviors>
  <endpointBehaviors>
    <behavior name="webBehaviour">
      <webHttp/>
    </behavior>
  </endpointBehaviors>
</behaviors>

I would say this was due to a client-side timeout setting. 我想说这是由于客户端超时设置造成的。 Do you have a client-side config or some other way to configure the wrapper? 您是否有客户端配置或其他方法来配置包装器?

It's hard to say as I don't quite know how your wrapper works but you would want to increase the timeouts on your bindings. 很难说,因为我不太了解您的包装器如何工作,但是您想增加绑定的超时时间。 eg 例如

        <binding openTimeout="00:10:00" 
             closeTimeout="00:10:00" 
             sendTimeout="00:10:00" 
             receiveTimeout="00:10:00">

See here for more details 看到这里更多细节

I'm going to answer my own question as I wanted to clarify a few things: 我要回答自己的问题,因为我想澄清一些事情:

  1. This has nothing to do with having invalid settings in the web.config as the problem was client-side related. 这与web.config中的无效设置无关,因为问题与客户端相关。 It is easy to assume that the problem is server side related but this was not the case in this instance. 很容易假设问题与服务器端有关,但在这种情况下并非如此。

  2. There is no point setting the ServiceModel (address, binding, contract) configuration in the app.config on the client-side as I'm calling the WebClient object which as far I'm aware is totally unaware of type of service I'm calling and these settings are quite specific to WCF and while my service is a WCF REST web service and does require a ServiceModel settings on the server end, the WebClient object is totally unaware of these. 当我调用WebClient对象时,在客户端的app.config中设置ServiceModel(地址,绑定,合同)配置毫无意义,据我所知,该对象完全不知道我所知道的服务类型调用和这些设置非常特定于WCF,而我的服务是WCF REST Web服务,并且确实需要服务器端的ServiceModel设置,但WebClient对象完全不知道这些。

  3. The answer to my problem was found in the article How can I change the time limit for webClient.UploadData()? 如何更改webClient.UploadData()的时限文章中找到了我的问题的答案 . After making the relevant changes, I test this thoroughly and it's also been deployed on the live site that were having the timeout problem and the problem has definitely been resolved when uploading a large amount of data. 进行相关更改之后,我将对其进行彻底的测试,并且还将其部署在存在超时问题的实时站点中,并且在上载大量数据时肯定已经解决了该问题。

Thanks. 谢谢。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM