.NET核心中的WCF(TransportWithMessageCredential) [英] WCF in .net core (TransportWithMessageCredential)

查看:102
本文介绍了.NET核心中的WCF(TransportWithMessageCredential)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我尝试在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'无效;

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)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆