我正在尝试使用来自.net核心3.1的SOAP1.2WCF服务。
我在.net框架4中有一个客户端在工作。它使用wsHttpBinding和TransportWithMessageCredential安全模式。
首先,我试图在我的wsHttpBinding核心客户端中使用.net,但是我得到了一个“平台不受支持”的异常。因此,我切换到了BasicHttpsBinding,但是当我调用一个函数时,这又导致了另一个例外:
ProtocolException: Content /xml;charset=utf-8不受服务https://domain/Service.svc支持。客户端绑定和服务绑定可能不匹配。
根据我的发现,BasicHttpsBinding用于SOAP1.1,wsHttpBinding用于SOAP1.2。
因此,根据https://stackoverflow.com/a/53336689,我尝试将Soap版本设置为1.2,但这给了我另一个例外:
SocketException:现有连接被远程主机强制关闭。
这是.net 4的工作配置(可读性略为缩写):
<bindings>
<wsHttpBinding>
<binding name="ServiceEndpoint"
messageEncoding="Text" textEncoding="utf-8">
<readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="16384"
maxBytesPerRead="4096" maxNameTableCharCount="16384" />
<reliableSession ordered="true" inactivityTimeout="00:10:00"
enabled="false" />
<security mode="TransportWithMessageCredential">
<transport clientCredentialType="None" proxyCredentialType="None"
realm="" />
<message clientCredentialType="UserName" negotiateServiceCredential="true"
algorithmSuite="Default" />
</security>
</binding>
</wsHttpBinding>
</bindings> 这是我的.net核心代码(不起作用):
var binding = new BasicHttpsBinding();
binding.Security.Transport.ClientCredentialType = HttpClientCredentialType.Basic;
binding.Security.Mode = BasicHttpsSecurityMode.TransportWithMessageCredential;
// Code from https://stackoverflow.com/a/53336689
var customTransportSecurityBinding = new CustomBinding(binding);
var textBindingElement = new TextMessageEncodingBindingElement
{
MessageVersion = MessageVersion.CreateVersion(EnvelopeVersion.Soap12, AddressingVersion.None)
};
// Replace text element to have Soap12 message version
customTransportSecurityBinding.Elements[1] = textBindingElement;
var serviceClient = new Svc.ServiceClient(customTransportSecurityBinding, new EndpointAddress("https://domain/Service.svc"));
serviceClient.ClientCredentials.UserName.UserName = "usr";
serviceClient.ClientCredentials.UserName.Password = "pwd";
var units = serviceClient.GetUnitsAsync().Result; // Exception here发布于 2020-09-04 01:28:04
服务器和客户端必须使用相同的绑定进行通信。您的服务器使用wsHttpBinding,但客户端使用BasicHttpsBinding,因此它们无法正常通信。

你是正确的。Core目前不支持wsHttpBinding,因此有两种解决方案:
1:将服务器的wsHttpBinding更改为BasicHttpBinding,核心不支持消息安全模式。对于核心中的WCF特性,您可以参考下面的链接:
https://github.com/dotnet/wcf/blob/master/release-notes/SupportedFeatures-v2.1.0.md
2:客户机使用.net框架而不是核心.
我建议你使用第二个解决方案。毕竟,核心对wcf的支持并不好。
如果问题仍然存在,请随时通知我。
https://stackoverflow.com/questions/63727340
复制相似问题