Web服务异常:接收对的HTTP响应时出错



我们正在与第三方公司合作,并使用他们的Web服务。除了一个需要字节[](File(作为输入的方法外,所有方法都可以正常工作。当我们调用该方法时,我们会得到以下异常:

接收对的HTTP响应时出错https://someaddress/Services/DefineMerchant.这可能是由于服务端点绑定未使用HTTP协议。这也可能是由于服务器中止了HTTP请求上下文(可能是由于服务关闭(。有关详细信息,请参阅服务器日志。基础连接已关闭:接收时发生意外错误。无法从传输连接读取数据:远程主机强制关闭了现有连接。远程主机强制关闭了现有连接

这是抛出异常的行:

using (var client = new SomeService.DefineMerchantsClient())
{
client.ClientCredentials.ServiceCertificate.Authentication.CertificateValidationMode = X509CertificateValidationMode.None;
client.ClientCredentials.UserName.UserName = "*****";
client.ClientCredentials.UserName.Password = "****";
var response = await client.AddRequestDocumentAsync(new MarketerDocEntity { File = requestData.File,   DocumentType = requestData.DocumentType, DocumentTrackingCode = requestData.DocumentTrackingCode });
}

这是我的App.config(控制台应用程序-Net Framework 4.7.2(:

<system.serviceModel>
<bindings>
<basicHttpBinding>
<binding name="BasicHttpBinding_IDefineMerchants"
maxBufferSize="2147483647" maxBufferPoolSize="2147483647" maxReceivedMessageSize="2147483647">
<security mode="TransportWithMessageCredential"  />
<readerQuotas maxDepth="2147483647" maxStringContentLength="2147483647"
maxArrayLength="2147483647" maxBytesPerRead="2147483647" maxNameTableCharCount="2147483647" />
</binding>

</basicHttpBinding>
</bindings>
<client>
<endpoint address="https://someaddress/Services/DefineMerchant" binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_IDefineMerchants" contract="SomeService.IDefineMerchants" name="BasicHttpBinding_IDefineMerchants"/>
</client>
</system.serviceModel>
<system.web>
<httpRuntime maxRequestLength="2147483647" executionTimeout="103600"/>
</system.web>

我也尝试过这行代码,但没有成功:

System.Net.ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12 | SecurityProtocolType.Tls11 | SecurityProtocolType.Tls;

这个异常是服务器端错误吗(我没有访问权限(?还是应该更改程序中的某些内容?谢谢

据我所知,可能有以下解决方案:

  1. 防火墙。有时会出现错误,因为防火墙已打开,请将其关闭,然后重试。

  2. 将以下代码添加到wcf服务器配置中。

    <dataContractSerializer maxItemsInObjectGraph="2147483647" />

  3. 检查客户端配置文件中是否定义了绑定BasicHttpBinding_IDefineMerchants。另外,如果您想更好地跟踪问题,可以将includeExceptionDetailInFaults值设置为true

如果有任何问题,请随时与我联系。

最新更新