【问题标题】:Error while invoking WCF web service调用 WCF Web 服务时出错
【发布时间】:2015-12-29 02:38:17
【问题描述】:

我在类库中引用了 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."

这是我的配置

<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>

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

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;

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

【问题讨论】:

标签: c# asp.net wcf


【解决方案1】:

您是否尝试将消息编码配置更改为MTOM?恕我直言,我认为你不应该同时使用配置文件和编程方式来配置你的 WCF 服务,因为它会让你很头疼。我建议坚持一个,它可以是配置文件或以编程方式。

【讨论】:

  • 在上面的代码中我已经提到了这一点。 binding.MessageEncoding = WSMessageEncoding.Mtom;
  • 我没有提到应该在配置文件中。
  • 我的最新配置为 URL_OF_Service" binding="customBinding" bindingConfiguration="CoreSoapBinding" contract="ContractName" name="CoreSoapPort" /> .serviceModel>
  • 您的最新配置在 URL_OF_Service 后面有分号?这是我客人的错字。
  • 这是一个错字。对不起
【解决方案2】:

由于绑定不匹配而发生错误。 您的服务器绑定是 BasicHttpBinding,而您的客户端是 CustomBinding。

由于您的服务正在使用 BasicHttpBinding,请尝试使用相同的绑定配置您的客户端,但是,如果您想使用 Soap12,则需要将您的服务器端配置为 CustomBinding,类似这样:

CustomBinding binding = new CustomBinding();
            SymmetricSecurityBindingElement ssbe =
                SecurityBindingElement.CreateSspiNegotiationBindingElement(true);
            // Add the SymmetricSecurityBindingElement to the BindingElementCollection.
            binding.Elements.Add(ssbe);
            binding.Elements.Add(new TextMessageEncodingBindingElement());
            binding.Elements.Add(new HttpTransportBindingElement());

您可以在此处阅读更多内容:https://msdn.microsoft.com/en-us/library/ms730305%28v=vs.110%29.aspx

希望对你有帮助。

【讨论】:

    猜你喜欢
    • 2015-11-11
    • 1970-01-01
    • 1970-01-01
    • 2014-03-31
    • 2012-07-13
    • 2016-08-03
    • 1970-01-01
    相关资源
    最近更新 更多