简体   繁体   中英

An error occurred while receiving the HTTP response to wcfservice.svc. This could be due to the service endpoint binding not using the HTTP protocol

I have a wcf service deployed under IIS 6.0. The service method accepts a list of objects and return the same list.

    List<CustomObject> ProcessImageData(List<CustomObject> lstData)

The object may contain large amount of html data. The service currently takes hardly a few seconds to fulfill the request but I am getting a tons of following 2 exceptions.

"The request channel timed out while waiting for a reply after 00:00:59.9989999. Increase the timeout value passed to the call to Request or increase the SendTimeout value on the Binding. The time allotted to this operation may have been a portion of a longer timeout."

"An error occurred while receiving the HTTP response to http://MyService.svc . This could be due to the service endpoint binding not using the HTTP protocol. This could also be due to an HTTP request context being aborted by the server (possibly due to the service shutting down). See server logs for more details."

Here is how my config files looks like.

web.Config (service) file

    <service behaviorConfiguration="WcfServices.Service1Behavior" name="WcfServices.HtmlToImageService">
    <endpoint address="" binding="wsHttpBinding" bindingConfiguration="LargeSizeMessages" contract="WcfServices.IHtmlToPngService">
      <identity>
        <dns value="localhost"/>
      </identity>
    </endpoint>
    <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"/>
   </service>

    <behaviors>
    <serviceBehaviors>
    <behavior name="WcfServices.Service1Behavior">
      <serviceThrottling maxConcurrentCalls="1000" maxConcurrentSessions="1000" maxConcurrentInstances="1000"/>
      <serviceMetadata httpGetEnabled="true"/>
      <dataContractSerializer maxItemsInObjectGraph="6553500"/>
      <serviceDebug includeExceptionDetailInFaults="true"/>
    </behavior>
   </behaviors>
    <wsHttpBinding>

       <binding name="LargeSizeMessages"
             maxBufferPoolSize="2147483647"
             maxReceivedMessageSize="2147483647">
      <readerQuotas
       maxDepth="32"
       maxStringContentLength="2147483647"
       maxArrayLength="2147483647"
       maxBytesPerRead="4096"
       maxNameTableCharCount="16384" />
    </binding>
  </wsHttpBinding>

Client Config file

    <wsHttpBinding>
      <binding name="WSHttpBinding_IHtmlToImageService" closeTimeout="00:10:00"
      openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:10:00"
      bypassProxyOnLocal="false" transactionFlow="false" hostNameComparisonMode="StrongWildcard"
      maxBufferPoolSize="2147483647" maxReceivedMessageSize="2147483647"
      messageEncoding="Text" textEncoding="utf-8" useDefaultWebProxy="true"
      allowCookies="false">
      <readerQuotas maxDepth="32" maxStringContentLength="2147483647"
        maxArrayLength="2147483647" maxBytesPerRead="4096" maxNameTableCharCount="16384" />
      <reliableSession ordered="true" inactivityTimeout="00:10:00"
        enabled="false" />
      <security mode="Message">
        <transport clientCredentialType="Windows" proxyCredentialType="None"
          realm="" />
        <message clientCredentialType="Windows" negotiateServiceCredential="true"
          algorithmSuite="Default" />
      </security>
    </binding>
    </wsHttpBinding>

One of the exceptions propose to increase the sendTimeout vakue which is currently set to 1 minute. I increased it but it didn't seem to improve anything and I still get these exceptions.

Question: Why am I getting these exceptions and what can I change to prevent this ?

Also, Here is an exception which is logged into Event Log on IIS server.

Exception Type: System.ArgumentException Message: Parameter is not valid. ParamName: NULL Data: System.Collections.ListDictionaryInternal TargetSite: Void .ctor(Int32, Int32, System.Drawing.Imaging.PixelFormat) HelpLink: NULL Source: System.Drawing

StackTrace Information


at System.Drawing.Bitmap..ctor(Int32 width, Int32 height, PixelFormat format) at System.Drawing.Bitmap..ctor(Int32 width, Int32 height) at WcfService.CreateBitmap(WebBrowser& browser) in C:_tfs\\ImagingSystem\\Development\\Dev\\Source\\Wcf\\WcfServices\\HtmlToPngService\\HtmlToPngService.svc.cs:line 126

You need to increase the timeout values in web.config (services), too. Something like this:

<bindings>
  <wsHttpBinding>
    <binding name="WSHttpBinding_IHtmlToImageService"
             openTimeout="00:10:00" 
             closeTimeout="00:10:00" 
             sendTimeout="00:10:00" 
             receiveTimeout="00:10:00">
    </binding>
  </wsHttpBinding>
</bindings> 

I suggest to review the following link:

https://msdn.microsoft.com/en-us/library/hh924831(v=vs.110).aspx

There can be a couple of things that can go wrong in this scenario. First, WCF is built to be very secure in its default configuration. That is why there is a limit to size of incoming requests. That limit is default rather small (65536 bytes). If your requests are larger than that, you need to configure the maxReceivedMessageSize and set it to the maximum number of bytes you want to support. Both on the server for incoming requests and the client for incoming responses. This is the likely cause for the second error, and you should be able to find a reference to this in the logging of your service.

Next, IIS has its own limit to the size of incoming requests. The default value for this limit is 30000000 bytes (roughly 30MB). If your requests are larger than that, you should also increase that limit (see here for more information), as WCF will not even see the incoming request as IIS will block it before it gets there. The timeout error you are describing is likely to occur in this scenario, because IIS will not even bother to send a response as it thinks it is under attack when it gets requests that exceed the configured limit.

Please think carefully about the values and bear in mind that maxReceivedMessageSize implicitly configures the buffer WCF will allocate to put the received message in. I've seen this value set to Int32.MaxValue in production systems. As a result the complete server could easily be brought down with a couple of huge concurrent requests, as the server tried to allocage 2GB of RAM to receive each of them.

you can first analyzed the exception. Do following exception Setting in visual studio and enable the "Common language Runtime exception".

在此处输入图片说明

mostly you can get the in depth details of exception using this. I got this exception because one of the field is mandatory in my model which I am getting null in response and due to this on client side my object is not able to get deserialized properly.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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