简体   繁体   English

.net 核心中的 WCF (TransportWithMessageCredential)

[英]WCF in .net core (TransportWithMessageCredential)

When I try to create a connection to a WCF client in dotnet core 2.0, I receive an platform unsupported error:当我尝试在 dotnet core 2.0 中创建与 WCF 客户端的连接时,收到平台不支持的错误:

System.PlatformNotSupportedException: 'The value 'TransportWithMessageCredential' is not supported in this context for the binding security property 'securityMode'.'

If I remove the BasicHttpSecurityMode , I receive an argument exception: System.ArgumentException: 'The provided URI scheme 'https' is invalid;如果我删除BasicHttpSecurityMode ,我会收到一个参数异常: System.ArgumentException: 'The provided URI scheme 'https' is invalid; expected 'http'.'应为“http”。

Code:代码:

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();

Anyone that found a workaround as this might be on the long term roadmap?任何找到解决方法的人,因为这可能在长期路线图上? https://github.com/dotnet/wcf/issues/8 https://github.com/dotnet/wcf/issues/8

This has been fixed by the latest packages.这已由最新的软件包修复。

  <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>  

Actually found a valid workaround, there is a package you can use for this: https://github.com/gravity00/SimpleSOAPClient实际上找到了一个有效的解决方法,您可以使用一个包: 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...让它像这样工作,作为一种魅力......

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM