.Net Core不支持WSHttpBinding

时间:2019-03-15 09:50:59

标签: wcf .net-core

将WSHttpBinding移至BasicHttpBinding。...

问题陈述:.net核心不支持 WSHttpBinding

当我的应用程序位于.Net 4.6中时,我正在使用WSHttpBinding通过以下代码创建与WCF的连接。

var binding = new WSHttpBinding(SecurityMode.TransportWithMessageCredential);
binding.Security.Transport.ClientCredentialType = HttpClientCredentialType.None;
binding.Security.Message.ClientCredentialType = MessageCredentialType.Certificate;
binding.Security.Message.EstablishSecurityContext = false;
X509Store store = new X509Store(StoreName.My, StoreLocation.CurrentUser);
store.Open(OpenFlags.ReadOnly);
var cert = store.Certificates.Find(X509FindType.FindByThumbprint, "Thumprint", true)[0];
result = new MyClient(binding, address);
client = result as ClientBase<TInterface>;                
client.ClientCredentials.ClientCertificate.Certificate = cert;

现在,我正在将应用程序迁移到.Net core,并且发现不支持 WSHttpBinding 。 我打算使用 BasicHttpBinding 进行以下更改:

    var binding = new BasicHttpBinding(BasicHttpSecurityMode.TransportWithMessageCredential);
    binding.Security.Transport.ClientCredentialType = HttpClientCredentialType.None;
    binding.Security.Message.ClientCredentialType = BasicHttpMessageCredentialType.Certificate;

对于 BasicHttpBinding ,以下代码没有任何规定:

 binding.Security.Message.EstablishSecurityContext = false;//This code is w.r.t. WSHttpBinding.

所以,我的问题是:这是否可以改变,还是我应该采取其他方法? 请协助!

3 个答案:

答案 0 :(得分:1)

<块引用>

在 .NET Core 和 .NET 5 中

BasicHttpBindingWSHttpBinding

通过安装 Nuget 包 System.ServiceModel.Http 版本 4.8.1 为我解决

https://www.nuget.org/packages/System.ServiceModel.Http

在 Visual Studio 的包控制台管理器中运行此命令

Install-Package System.ServiceModel.Http

答案 1 :(得分:0)

我做了同样的事情(从FULL .NET FRAMEWORK移到.NET CORE PROJECT),发现there is NO SUPPORT for WCF ...

我所做的是:

1-Create a .NET STANDARD LIB PROJ ..指的是您的SOAP端点(它支持WCF)

2-{{​​1}}

希望对您有帮助!

喜欢: enter image description here

,然后像这样引用它:

enter image description here

答案 2 :(得分:0)

.net core 3.1支持

Wshttpbinding。

  1.   You should use the Nuget --System.private.serviceModel to get the wshttp binding methods in .NET core 3.1
    

enter image description here

  1.   Below are the Nuget Packages that will be required.
    

enter image description here