gpt4 book ai didi

c# - 调用 WCF Web 服务时出错

转载 作者:太空狗 更新时间:2023-10-29 23:50:14 24 4
gpt4 key购买 nike

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

然后我在应用程序中创建绑定(bind)对象并传递给服务。

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;

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

最佳答案

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

关于c# - 调用 WCF Web 服务时出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32880841/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com