我尝试使用WCF客户端从.NET控制台应用程序连接到NetSuite OpenAir API。我通过添加服务连接并使用以下WSDL生成了代理:http://sandbox.openair.com/wsdl.pl?wsdl&style=document
只要HTTP响应不超过特定大小,登录和读取数据就可以正常工作。发生这种情况时,将发生System.IO.InvalidDataException。异常消息是“块长度与其补码不匹配”。
以下是例外情况详细信息:
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>
看看异常情况,它似乎与DEFLATE减压算法有关,该算法在内部由WCF调用。似乎发生了一些缓冲区溢出。我可以定义一个自定义绑定并禁用压缩,但是我想保留它作为最后的手段。
任何提示如何解决此问题?非常感谢您的帮助!