1

I'm getting the following exception The operation has timed out when calling my WCF REST service.

I basically have a WCF Web Service project and a web site which references the compiled WCF assembly. 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.

The problem only occurs if I try to insert a large amount of data.

The web.config contains the following info:

<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. All http request are made via the WebClient which is called the sdk. 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.

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.

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

Any ideas?

Thanks.

UPDATE:

I've added additional info about my web.config (i.e. service & behaviour definitions):

<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>
Thierry
  • 6,142
  • 13
  • 66
  • 117

2 Answers2

0

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. e.g.

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

See here for more details

Mark
  • 2,926
  • 3
  • 28
  • 31
  • Hi Mark, I don't have anything set in the client-side alright. That's one of the thing I was wondering about. Any chance of showing me what I should be setting on the client-side? I'm not even sure it would read the app.config as remember that I'm calling the WebClient rather than having a reference to the web service. – Thierry May 28 '15 at 01:19
  • Hi again Mark, you were correct. I found this article: http://stackoverflow.com/questions/1237966/how-can-i-change-the-time-limit-for-webclient-uploaddata and once I increase the timeout of my WebClient, the problem seems to have gone away. I've set it to 10 minutes and left it on my breakpoint for over 5 minutes and no problem. I've ran the same "upload" 5 times now and not once have I received the original error or the second one I mentioned above, so looking good but I'll have to wait and see how it goes with the client tomorrow. Thanks again. – Thierry May 28 '15 at 02:04
0

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

  3. The answer to my problem was found in the article How can I change the time limit for 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.

Community
  • 1
  • 1
Thierry
  • 6,142
  • 13
  • 66
  • 117