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

xyhw6mcr  于 2022-11-15  发布在  其他
关注(0)|答案(1)|浏览(250)

我们正在与第三方公司合作,并使用他们的Web服务。除了一个需要byte[](File)作为输入的方法之外,所有方法都工作正常。当我们调用该方法时,会出现以下异常:
接收对https://someaddress/Services/DefineMerchant的HTTP响应时出错。这可能是因为服务终结点绑定未使用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;

这个异常是服务器端错误(我没有访问权限)吗?或者我应该在程序中更改一些内容吗?谢谢!

mrzz3bfm

mrzz3bfm1#

据我所知,可能有以下几种解决办法:
1.防火墙。有时会因为防火墙打开而出错,请将其关闭,然后重试。
1.将以下代码添加到wcf服务器配置中。
<dataContractSerializer maxItemsInObjectGraph="2147483647" />
1.检查客户端配置文件中是否定义了绑定BasicHttpBinding_IDefineMerchants。另外,如果希望更好地跟踪问题,可以将includeExceptionDetailInFaults值设置为true
如果有任何问题,请随时与我联系。

相关问题