.NetStandard 或 .NET 核心中的 WSHttpBinding
WSHttpBinding in .NetStandard or .NET core
我想在我的应用程序中集成 NMVS 协议,该应用程序提供用于测试的 wsdl 文件,这些文件是在 .net 框架库中编写的示例代码。
我想在 .netstandard、.netcore 或 UWP 应用程序中对其进行测试,但 wsdl 文件仅支持 "WSHttpBinding",而在 .netstandard、.net core 和 UWP 中不受支持。
<wsdl:binding name="WSHttpBinding_ISinglePackServices" type="ns:ISinglePackServices">
WSHttpBinding binding = new WSHttpBinding();
binding.Security.Mode = SecurityMode.Transport;
binding.Security.Transport.ClientCredentialType = HttpClientCredentialType.Certificate;
我使用了 basichttpbinding 但我收到错误 "The content type application/soap+xml; charset=UTF-8 of the response message does not match the content type of the binding (text/xml; charset=utf-8)."
解决此问题的其他方法是什么?
谢谢
伊姆兰汗
这是您的问题的解决方案:
var transportSecurityBinding = new BasicHttpBinding();
transportSecurityBinding.Security.Mode = BasicHttpSecurityMode.Transport;
transportSecurityBinding.Security.Transport.ClientCredentialType = HttpClientCredentialType.Certificate;
var customTransportSecurityBinding = new CustomBinding(transportSecurityBinding);
var textBindingElement = new TextMessageEncodingBindingElement
{
MessageVersion = MessageVersion.CreateVersion(EnvelopeVersion.Soap12, AddressingVersion.None)
};
// Replace text element to have Soap12 message version
customTransportSecurityBinding.Elements[0] = textBindingElement;
我想在我的应用程序中集成 NMVS 协议,该应用程序提供用于测试的 wsdl 文件,这些文件是在 .net 框架库中编写的示例代码。
我想在 .netstandard、.netcore 或 UWP 应用程序中对其进行测试,但 wsdl 文件仅支持 "WSHttpBinding",而在 .netstandard、.net core 和 UWP 中不受支持。
<wsdl:binding name="WSHttpBinding_ISinglePackServices" type="ns:ISinglePackServices">
WSHttpBinding binding = new WSHttpBinding();
binding.Security.Mode = SecurityMode.Transport;
binding.Security.Transport.ClientCredentialType = HttpClientCredentialType.Certificate;
我使用了 basichttpbinding 但我收到错误 "The content type application/soap+xml; charset=UTF-8 of the response message does not match the content type of the binding (text/xml; charset=utf-8)."
解决此问题的其他方法是什么?
谢谢 伊姆兰汗
这是您的问题的解决方案:
var transportSecurityBinding = new BasicHttpBinding();
transportSecurityBinding.Security.Mode = BasicHttpSecurityMode.Transport;
transportSecurityBinding.Security.Transport.ClientCredentialType = HttpClientCredentialType.Certificate;
var customTransportSecurityBinding = new CustomBinding(transportSecurityBinding);
var textBindingElement = new TextMessageEncodingBindingElement
{
MessageVersion = MessageVersion.CreateVersion(EnvelopeVersion.Soap12, AddressingVersion.None)
};
// Replace text element to have Soap12 message version
customTransportSecurityBinding.Elements[0] = textBindingElement;