【问题标题】:.Net Core does not support WSHttpBinding.Net Core 不支持 WSHttpBinding
【发布时间】:2019-03-15 09:50:59
【问题描述】:

将 WSHttpBinding 移动到 BasicHttpBinding....

问题说明:WSHttpBinding 在 .Net 核心中不受支持。

当我的应用程序在 .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 核心,我发现不支持 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.

所以,我的问题是:是否可以进行这种更改,或者我应该采取其他方式? 请帮忙!

【问题讨论】:

  • 我认为它不起作用。目前Core项目中的Basichttpbinding只能调用security=none的Wshttpbinding。请参考我之前的回复。 stackoverflow.com/questions/54635079/…
  • 是的!,它不起作用。我正在尝试使用以下 federico scamuzzi 的建议,但这对我不起作用。
  • 我将以用户的声音提交您的请求。谢谢。您也可以自己将其发布在 Github 问题上。 github.com/dotnet/wcf/issues

标签: wcf .net-core


【解决方案1】:

在 .Net 5 中,Wshttpbinding 不再支持 SecurityMode 消息。请改用运输。但是,它不如 Message 安全。

var binding = new WSHttpBinding();
binding.Security.Mode = SecurityMode.Transport;

https://docs.microsoft.com/en-us/dotnet/framework/wcf/how-to-set-the-security-mode

【讨论】:

    【解决方案2】:

    .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
      

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

    【讨论】:

      【解决方案3】:

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

      【讨论】:

        【解决方案4】:

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

        我所做的是:

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

        2 - Reference your LIB to a .NET CORE PROJECT

        希望对你有帮助!!

        喜欢:

        然后像这样引用它:

        【讨论】:

        • 如果它帮助你记住评价它! ;-) 谢谢!!
        • 我无法创建绑定,因为下面的代码不起作用。如何创建绑定。顺便说一句,我已经在 .net 标准 2.0 中创建了类库。 var binding = new WSHttpBinding(SecurityMode.TransportWithMessageCredential);
        • 在标准项目中添加一个新的连接服务 (wcf) .. 然后在 .net 核心项目中引用您的标准项目(在项目中右键单击,然后将引用添加到您的 dll)
        • .net 标准不支持我想在自定义绑定中使用的以下方法,同时调用 WCF 服务。 var securityBindingElement = SecurityBindingElement.CreateMutualCertificateBindingElement(MessageSecurityVersion.WSSecurity10WSTrust13WSSecureConversation13WSSecurityPolicy12BasicSecurityProfile10);
        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多