Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

.Net Core does not support WSHttpBinding

Tags:

.net-core

wcf

Moving WSHttpBinding to BasicHttpBinding....

Problem statement: WSHttpBinding is not supported in .Net core.

When my application was in .Net 4.6, I was using WSHttpBinding to create the connection with WCF with below code.

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;

Now I am migrating my application to .Net core and i found there is no support to WSHttpBinding. I am planning to move with BasicHttpBinding and made the following changes:

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

With BasicHttpBinding there is no provision to below code:

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

So, my question is: Does this changes okay to go with or I should do some other way around? Please assist!

like image 410
Bikram Avatar asked Mar 15 '19 09:03

Bikram


1 Answers

in .NET Core & .NET 5

BasicHttpBinding and WSHttpBinding

Solved for me by installing Nuget package System.ServiceModel.Http Version 4.8.1

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

Run this command in Package Console Manager in Visual Studio

Install-Package System.ServiceModel.Http
like image 165
Abdelrahman Gobarah Avatar answered Oct 12 '22 07:10

Abdelrahman Gobarah