.net 核心中的 WCF (TransportWithMessageCredential)

Jel*_*sch 6 .net c# wcf .net-core asp.net-core

当我尝试在 dotnet core 2.0 中创建与 WCF 客户端的连接时,收到平台不支持的错误:

System.PlatformNotSupportedException: 'The value 'TransportWithMessageCredential' is not supported in this context for the binding security property 'securityMode'.'
Run Code Online (Sandbox Code Playgroud)

如果我删除BasicHttpSecurityMode,我会收到一个参数异常: System.ArgumentException: 'The provided URI scheme 'https' is invalid; 应为“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();
Run Code Online (Sandbox Code Playgroud)

任何找到解决方法的人,因为这可能在长期路线图上? https://github.com/dotnet/wcf/issues/8

Bil*_*ill 11

这已由最新的软件包修复。

  <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>  
Run Code Online (Sandbox Code Playgroud)

  • 这个关键点救了我的命。我正在使用 4.4.0,但它从来没有工作过。使用 4.6.0 版本我已经解决了我的问题。此外,您可以在.net框架中使用单独的程序集,也可以在.net core中使用 (3认同)

Jel*_*sch 2

实际上找到了一个有效的解决方法,有一个包可以用于此目的: 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);
Run Code Online (Sandbox Code Playgroud)

让它像这样工作,作为一种魅力......