调用WCF Web服务时出错

Pra*_*eep 5 c# asp.net wcf

我在类库中引用了WCF服务,在Web应用程序中引用了该类库.当我尝试从服务调用一个方法时,我遇到异常.

"Content Type multipart/related; type="application/xop+xml";start="<http://tempuri.org/0>";boundary="uuid:901bc2e6-6d57-4363-9f99-41ca4884ce16+id=1";start-info="text/xml" was not supported by service https://URL_OF_Service/.  The client and service bindings may be mismatched."
Run Code Online (Sandbox Code Playgroud)

这是我的配置

<system.serviceModel>
    <bindings>
      <customBinding>
        <binding name="CoreSoapBinding">
          <textMessageEncoding messageVersion="Soap12" />
          <httpTransport />
        </binding>
      </customBinding>
    </bindings>
    <client>
      <endpoint address="https://URL_OF_Service/" binding="customBinding"
          bindingConfiguration="CoreSoapBinding" contract="ContractName"
          name="CoreSoapPort" />
    </client>
  </system.serviceModel>
Run Code Online (Sandbox Code Playgroud)

我在应用程序中创建了绑定对象并传递给了服务.

BasicHttpBinding binding = new BasicHttpBinding()
            binding.Security.Mode = BasicHttpSecurityMode.Transport;
            binding.Security.Transport.ClientCredentialType = HttpClientCredentialType.Basic;
            binding.Name = "CoreSoapPort";
            binding.Security.Message.ClientCredentialType = BasicHttpMessageCredentialType.UserName;
            binding.BypassProxyOnLocal = false;
            binding.UseDefaultWebProxy = true;
            binding.MessageEncoding = WSMessageEncoding.Mtom;
            binding.AllowCookies = false;
            binding.TransferMode = TransferMode.Buffered;
            binding.HostNameComparisonMode = HostNameComparisonMode.StrongWildcard;
            Encoding textencoding = Encoding.UTF8;
            binding.TextEncoding = textencoding;
            binding.MaxReceivedMessageSize = Int32.MaxValue;
Run Code Online (Sandbox Code Playgroud)

我尝试将配置更改为多个以匹配服务器配置.但没有运气.

jta*_*loc 0

您是否尝试将消息编码配置更改为MTOM?恕我直言,我认为您不应该同时使用配置文件和编程方式来配置 WCF 服务,因为这会给您带来很多麻烦。我建议坚持使用一种,它可以是配置文件,也可以是编程方式。