WSHttpBinding in .NetStandard or .NET core
Asked Answered
F

1

8

I want to integrate NMVS protocol in my application which is providing wsdl files for testing which is written sample code in .net framework library.

I want to test it in .netstandard, .netcore or UWP app but wsdl files only support to "WSHttpBinding" which is not supported in .netstandard, .net core and UWP.

 <wsdl:binding name="WSHttpBinding_ISinglePackServices" type="ns:ISinglePackServices">



WSHttpBinding binding = new WSHttpBinding();
 binding.Security.Mode =  SecurityMode.Transport;
 binding.Security.Transport.ClientCredentialType = HttpClientCredentialType.Certificate;

I used basichttpbinding but I am getting error that says "The content type application/soap+xml; charset=UTF-8 of the response message does not match the content type of the binding (text/xml; charset=utf-8)."

What are the other ways to troubleshoot this issue?

Thanks Imrankhan

Figureground answered 15/11, 2018 at 14:43 Comment(3)
WSDL is a SOAP standard. The WS binding means it supports the WS-* interoperability standards. That's what WCF uses. If you use Add Service Reference or Add Connected Service Visual Studio will create a WCF proxy that takes care of all this. Why are you trying to write the bindings by hand?Sternforemost
Which .NET Standard version are you trying to target? The older .NET Core/Standard versions didn't support all types required for WCF. The latest ones do. This means that even if Add Connected Services doesn't work, you can generate the proxy in a Full Framework project, copy the files to a Standard 2.0 project, compile it and use itSternforemost
NMVS has provided some .wsdl file that I have added using Add connected service. Now to call some methods I need to setup secure mode and client credential type that you can see above wshttpbinding code. and that xml part is from wsdl file.Figureground
L
15

Here is a solution for your problem :

var transportSecurityBinding = new BasicHttpBinding();
transportSecurityBinding.Security.Mode = BasicHttpSecurityMode.Transport;
transportSecurityBinding.Security.Transport.ClientCredentialType = HttpClientCredentialType.Certificate;

var customTransportSecurityBinding = new CustomBinding(transportSecurityBinding);

var textBindingElement = new TextMessageEncodingBindingElement
{
      MessageVersion = MessageVersion.CreateVersion(EnvelopeVersion.Soap12, AddressingVersion.None)
};

// Replace text element to have Soap12 message version
customTransportSecurityBinding.Elements[0] = textBindingElement;
Larimer answered 16/11, 2018 at 11:9 Comment(2)
Thanks, it saved a huge time of my life. Since my URL is not https, it works for me by setting BasicHttpSecurityMode.None and HttpClientCredentialType.None.Erector
Mr. Giannone, you are a genius. If, like me, you have a mix of old and new SOAP services, and you want to regenerate the proxy code and use channel factories to access (you, know, 21st century techniques), the differences between transports and headers can be mind boggling. This answer should be elevated in a number of SO posts.Heatherheatherly

© 2022 - 2024 — McMap. All rights reserved.