收到对wcfservice.svc的HTTP响应时发生错误。这可能是由于服务端点绑定不使用HTTP协议

时间:2016-03-09 20:38:01

标签: c# web-services wcf

我在IIS 6.0下部署了一个wcf服务。 service方法接受对象列表并返回相同的列表。

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

该对象可能包含大量的html数据。该服务目前只需几秒钟即可完成请求,但我收到了大量的以下2个例外情况。

&#34;请求频道在00:00:59.9989999之后等待回复时超时。增加传递给Request的调用的超时值或增加Binding上的SendTimeout值。分配给此操作的时间可能是较长超时的一部分。&#34;

&#34;接收到http://MyService.svc的HTTP响应时发生错误。这可能是由于服务端点绑定不使用HTTP协议。这也可能是由于服务器中止HTTP请求上下文(可能是由于服务关闭)。有关详细信息,请参阅服务器日志。&#34;

以下是我的配置文件的样子。

web.Config(服务)文件

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

客户端配置文件

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

其中一个例外是建议增加当前设置为1分钟的sendTimeout vakue。我增加了它,但它似乎没有改善任何东西,我仍然得到这些例外。

问题: 为什么我会收到这些例外情况以及我可以更改哪些内容来阻止这种情况?

此外,这是一个例外,它记录在IIS服务器上的事件日志中。

异常类型:System.ArgumentException 消息:参数无效。 ParamName:NULL 数据:System.Collections.ListDictionaryInternal TargetSite:Void .ctor(Int32,Int32,System.Drawing.Imaging.PixelFormat) HelpLink:NULL 来源:System.Drawing

StackTrace信息

System.Drawing.Bitmap..ctor上的

(Int32宽度,Int32高度,PixelFormat格式)    在System.Drawing.Bitmap..ctor(Int32宽度,Int32高度)    在C:_tfs \ ImagingSystem \ Development \ Dev \ Source \ Wcf \ WcfServices \ HtmlToPngService \ HtmlToPngService.svc.cs中的WcfService.CreateBitmap(WebBrowser&amp; browser):第126行

3 个答案:

答案 0 :(得分:0)

您还需要增加web.config(服务)中的超时值。像这样:

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

我建议查看以下链接:

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

答案 1 :(得分:0)

在这种情况下可能会出现一些问题。首先,WCF的默认配置非常安全。这就是为什么传入请求的大小有限。该限制默认为相当小(65536字节)。如果您的请求大于此值,则需要配置maxReceivedMessageSize并将其设置为您要支持的最大字节数。服务器上的传入请求和客户端的传入响应。这可能是导致第二个错误的原因,您应该能够在服务日志记录中找到对此的引用。

接下来,IIS对传入请求的大小有自己的限制。此限制的默认值为30000000字节(大约30MB)。如果您的请求大于此,您还应该增加该限制(有关详细信息,请参阅here),因为WCF甚至不会看到传入的请求,因为IIS会在它到达之前阻止它。您正在描述的超时错误很可能发生在这种情况下,因为当IIS收到超出配置限制的请求时,IIS甚至不会发送响应,因为它认为它正受到攻击。

请认为仔细考虑这些值,并记住maxReceivedMessageSize隐式配置缓冲区WCF将分配以将接收到的消息放入。我已经看到这个值设置为生产系统中的Int32.MaxValue。因此,服务器试图分配2GB的RAM来接收每个请求,因此整个服务器很容易被一些巨大的并发请求关闭。

答案 2 :(得分:0)

您可以首先分析异常。在Visual Studio中执行以下异常设置,并启用“公共语言运行时异常”。

enter image description here

大多数情况下,您可以使用此方法获得异常的详细信息。 我收到此异常的原因是,在我的模型中该字段是强制性的,因此我得到的响应为null,并且由于在客户端,我的对象无法正确反序列化。

相关问题