问题描述
当我尝试在 dotnet core 2.0 中创建与 WCF 客户端的连接时,收到平台不支持的错误:
When I try to create a connection to a WCF client in dotnet core 2.0, I receive an platform unsupported error:
System.PlatformNotSupportedException: 'The value 'TransportWithMessageCredential' is not supported in this context for the binding security property 'securityMode'.'
如果我删除 BasicHttpSecurityMode
,我会收到一个参数异常:System.ArgumentException: '提供的 URI 方案 'https' 无效;应为http".
If I remove the BasicHttpSecurityMode
, I receive an argument exception: System.ArgumentException: 'The provided URI scheme 'https' is invalid; expected 'http'.'
代码:
ChannelFactory<BlackBoxContract> factory = null;
BlackBoxContract serviceProxy = null;
Binding binding = null;
binding = new BasicHttpBinding(BasicHttpSecurityMode.TransportWithMessageCredential);
factory = new ChannelFactory<BlackBoxContract>(binding, new EndpointAddress("https:......."));;
serviceProxy = factory.CreateChannel();
有人找到了解决方法,因为这可能是长期路线图吗?https://github.com/dotnet/wcf/issues/8
Anyone that found a workaround as this might be on the long term roadmap?https://github.com/dotnet/wcf/issues/8
推荐答案
实际上找到了一个有效的解决方法,有一个包可以用于此:https://github.com/gravity00/SimpleSOAPClient
Actually found a valid workaround, there is a package you can use for this:https://github.com/gravity00/SimpleSOAPClient
using SimpleSOAPClient;
using SimpleSOAPClient.Handlers;
using SimpleSOAPClient.Helpers;
using SimpleSOAPClient.Models;
using SimpleSOAPClient.Models.Headers;
...
_client = SoapClient.Prepare().WithHandler(new DelegatingSoapHandler());
_client.HttpClient.DefaultRequestHeaders.Clear();
_client.HttpClient.DefaultRequestHeaders.Add("SOAPAction", "Action...");
var requestEnvelope = SoapEnvelope
.Prepare()
.Body(request)
.WithHeaders(KnownHeader.Oasis.Security.UsernameTokenAndPasswordText(Username, Password));
var responseEnvelope = _client.Send(Url, "CanNotBeEmpty", requestEnvelope);
让它像这样工作,作为一种魅力......
Got it to work like this, as a charm...
这篇关于.net 核心中的 WCF (TransportWithMessageCredential)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!