当我尝试在dotnet core 2.0中创建与WCF客户端的连接时,我收到一个不支持的平台错误:
System.PlatformNotSupportedException: 'The value 'TransportWithMessageCredential' is not supported in this context for the binding security property 'securityMode'.'
如果删除BasicHttpSecurityMode
,我会收到一个参数异常:
System.ArgumentException:'提供的URI方案' https'是无效的;预期' 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
答案 0 :(得分:1)
实际上找到了一个有效的解决方法,你可以使用一个包: 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);
让它像这样工作,作为魅力......
答案 1 :(得分:1)
此问题已由最新软件包修复。
<ItemGroup>
<PackageReference Include="System.ServiceModel.Duplex" Version="4.6.0" />
<PackageReference Include="System.ServiceModel.Http" Version="4.6.0" />
<PackageReference Include="System.ServiceModel.NetTcp" Version="4.6.0" />
<PackageReference Include="System.ServiceModel.Security" Version="4.6.0" />
</ItemGroup>