WCF 服务提高 System.IO.InvalidDataException

WCF service raises System.IO.InvalidDataException

我尝试使用 WCF 客户端从 .NET 控制台应用程序连接到 NetSuite OpenAir API。我通过添加服务连接并使用以下 WSDL 生成代理:http://sandbox.openair.com/wsdl.pl?wsdl&style=document

只要 HTTP 响应不超过特定大小,登录和读取数据就可以正常工作。当发生这种情况时,会出现 System.IO.InvalidDataException。异常消息是 "Block length does not match with its complement".

这些是异常详细信息:

System.IO.InvalidDataException
  HResult=0x80131501
  Message=Block length does not match with its complement.
  Source=mscorlib
  StackTrace:
   at System.Runtime.Remoting.Proxies.RealProxy.HandleReturnMessage(IMessage reqMsg, IMessage retMsg)
   at System.Runtime.Remoting.Proxies.RealProxy.PrivateInvoke(MessageData& msgData, Int32 type)
   at TestService.OASandbox.OAirServiceHandler.read(readRequest1 request)
   at TestService.OASandbox.OAirServiceHandlerClient.TestService.OASandbox.OAirServiceHandler.read(readRequest1 request) in TestService\Connected Services\OASandbox\Reference.cs:line 43089
   at TestService.OASandbox.OAirServiceHandlerClient.read(SessionHeader SessionHeader, ReadRequest[] method) in TestService\Connected Services\OASandbox\Reference.cs:line 43096
   at TestService.Program.Main() in TestService\Program.cs:line 105

我用Fiddler来找出转折点是什么。似乎是在 HTTP 响应的 Content-Length 大于 10000 字节时引发异常。响应本身是完全完整的:当我使用 Fiddler 对其进行分析时,它可以被破译(因为它是一个 SSL 连接)并且 OpenAir 发回的完整 XML 被揭示出来。所以一定是.NET代码有问题。

WCF 绑定在我的 app.config 中定义如下:

<system.serviceModel>
  <bindings>
    <basicHttpBinding>
      <binding name="OAirServiceSoapBinding" maxBufferPoolSize="2147483647" maxReceivedMessageSize="2147483647" maxBufferSize="2147483647">
        <security mode="Transport" />
        <readerQuotas maxDepth="200" maxStringContentLength="83886089" maxArrayLength="163841" maxBytesPerRead="2147483647" maxNameTableCharCount="16384"/>
      </binding>
      <binding name="OAirServiceSoapBinding1" maxBufferPoolSize="2147483647" maxReceivedMessageSize="2147483647" maxBufferSize="2147483647">
        <readerQuotas maxDepth="200" maxStringContentLength="83886089" maxArrayLength="163841" maxBytesPerRead="2147483647" maxNameTableCharCount="16384"/>
      </binding>
    </basicHttpBinding>
  </bindings>
  <client>
    <endpoint address="https://sandbox.openair.com/soapdoc" binding="basicHttpBinding"
        bindingConfiguration="OAirServiceSoapBinding" contract="OASandbox.OAirServiceHandler"
        name="OAirService" />
  </client>
</system.serviceModel>

查看异常似乎与 WCF 内部调用的 DEFLATE 解压缩算法有关。似乎发生了一些缓冲区溢出。我可以定义一个自定义绑定并禁用压缩,但我想保留它作为最后的手段。

有任何解决此问题的线索吗?非常感谢任何帮助!

我正在使用 NetSuite SuiteTalk WSDL。我将其添加为 Web 参考,然后将其作为设置添加到我的配置文件中的 "applicationSettings":

我认为问题在于您绑定到 SOAP 服务只允许返回特定大小的数据。如果将 WSDL 添加为 Web 引用,则不应应用此限制。我添加我的如下:

1) 在您的 WCF 服务中右键单击 "References",然后 select "Add Service Reference"。

2) Select "Advanced":

3) 添加网络引用:

4) 粘贴您的 WSDL 参考并单击文本字段旁边的箭头。等待 WSDL 出现在文本块中,然后单击 "add reference"。:

希望对您有所帮助!