7

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!

Bikram
  • 483
  • 6
  • 16
  • I don't think it works. At present only Wshttpbinding with security=none could be invocated by Basichttpbinding in Core project. Please refer to my privious reply. https://stackoverflow.com/questions/54635079/wshttpbinding-workarounds-in-net-core/54664674#54664674 – Abraham Qian Mar 18 '19 at 07:18
  • Yeah!, it won't work. I was trying with below federico scamuzzi suggestion but that to didn't work for me. – Bikram Mar 18 '19 at 08:48
  • I will submit your request as user's voice. thanks. you could also post it on Github issue by yourself. https://github.com/dotnet/wcf/issues – Abraham Qian Mar 18 '19 at 09:05

4 Answers4

4

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
Abdelrahman Gobarah
  • 1,544
  • 2
  • 12
  • 29
3

In .Net 5, Wshttpbinding no longer supports SecurityMode Message. Use Transport instead. However, it is not as secure as Message.

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

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

Luke Phillips
  • 3,372
  • 1
  • 11
  • 15
2

Wshttpbinding is supported in .net core 3.1.

  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

Bikram
  • 483
  • 6
  • 16
0

I did the same (move from FULL .NET FRAMEWORK to .NET CORE PROJECT) and i found there is NO SUPPORT for WCF ...

what i have done is:

1 - Create a .NET STANDARD LIB PROJ .. with reference to your SOAP endpoint (it support WCF)

2 - Reference your LIB to a .NET CORE PROJECT

hope it helps you!!

like: enter image description here

and then reference it like:

enter image description here

federico scamuzzi
  • 3,708
  • 1
  • 17
  • 24
  • if it helps you remeber to rate it !! ;-) thnx!! – federico scamuzzi Mar 15 '19 at 13:10
  • I am unable to create the binding because of below code is not working. How to create a binding. By the way i have created the class library in .net standard 2.0. var binding = new WSHttpBinding(SecurityMode.TransportWithMessageCredential); – Bikram Mar 18 '19 at 07:11
  • in the standard proj add a new connected service (wcf) .. then reference your stardard proj in the .net core proj (on project right click and then add refrence to your dll) – federico scamuzzi Mar 18 '19 at 08:54
  • .net standard does not support the below method i wanted to use in custom binding, while calling the WCF services. var securityBindingElement = SecurityBindingElement.CreateMutualCertificateBindingElement(MessageSecurityVersion.WSSecurity10WSTrust13WSSecureConversation13WSSecurityPolicy12BasicSecurityProfile10); – Bikram Mar 22 '19 at 12:12