1

I'm trying to consume a SOAP 1.2 WCF service from .net core 3.1.
I have a client in .net framework 4 working. It uses wsHttpBinding with security mode TransportWithMessageCredential.

First I tried to use wsHttpBinding in my .net core client but I got a "Platform not supported" exception. So I switched to BasicHttpsBinding but that led to another exception when I called a function:

ProtocolException: Content Type text/xml; charset=utf-8 was not supported by service https://domain/Service.svc. The client and service bindings may be mismatched.

From what I found BasicHttpsBinding is for Soap 1.1 and wsHttpBinding is for Soap 1.2.
So I tried setting the Soap-version to 1.2 according to https://stackoverflow.com/a/53336689 but that gave me another exception:

SocketException: An existing connection was forcibly closed by the remote host.

This is the working config for .net 4 (somewhat abbreviated for readability):

<bindings>
        <wsHttpBinding>
            <binding name="ServiceEndpoint" 
                messageEncoding="Text" textEncoding="utf-8">
                <readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="16384"
                    maxBytesPerRead="4096" maxNameTableCharCount="16384" />
                <reliableSession ordered="true" inactivityTimeout="00:10:00"
                    enabled="false" />
                <security mode="TransportWithMessageCredential">
                    <transport clientCredentialType="None" proxyCredentialType="None"
                        realm="" />
                    <message clientCredentialType="UserName" negotiateServiceCredential="true"
                        algorithmSuite="Default" />
                </security>
            </binding>
        </wsHttpBinding>
    </bindings>      

This is my .net core code (not working):

var binding = new BasicHttpsBinding();
binding.Security.Transport.ClientCredentialType = HttpClientCredentialType.Basic;
binding.Security.Mode = BasicHttpsSecurityMode.TransportWithMessageCredential;
// Code from https://stackoverflow.com/a/53336689
var customTransportSecurityBinding = new CustomBinding(binding);
var textBindingElement = new TextMessageEncodingBindingElement
{
    MessageVersion = MessageVersion.CreateVersion(EnvelopeVersion.Soap12, AddressingVersion.None)
};
// Replace text element to have Soap12 message version
customTransportSecurityBinding.Elements[1] = textBindingElement;

var serviceClient = new Svc.ServiceClient(customTransportSecurityBinding, new EndpointAddress("https://domain/Service.svc"));
serviceClient.ClientCredentials.UserName.UserName = "usr";
serviceClient.ClientCredentials.UserName.Password = "pwd";
var units = serviceClient.GetUnitsAsync().Result; // Exception here
Björn
  • 3,098
  • 2
  • 26
  • 40

1 Answers1

0

The server and the client must use the same binding to communicate. Your server uses wsHttpBinding but the client uses BasicHttpsBinding, so they cannot communicate normally.

enter image description here

You are right. Core does not currently support wsHttpBinding, so there are two solutions:

1:Change the wsHttpBinding of the server to BasicHttpBinding, and the core does not support the Message security mode. For the WCF features in the Core, you can refer to the link below:

https://github.com/dotnet/wcf/blob/master/release-notes/SupportedFeatures-v2.1.0.md

2:The client uses the .net framework instead of core.

I suggest you use the second solution. After all, core's support for wcf is not good.

Feel free to let me know if the problem persists.

Ding Peng
  • 3,702
  • 1
  • 5
  • 8
  • silly question, but why do WCF call from .Net core at all ? This can all be done using a simple HttpClient POST call. You would need to serialize/deserialize your request responses, but that can easily be done by creating the required classes using XSD or one of the many online tools. I was in a similar situation when porting an old WCF client to .net core and ended up going the HttpClient route. Simpler, and might I say, faster too. – Ceemah Four Sep 04 '20 at 03:08
  • @CeemahFour Well, if there was a way to make it work "out of the box" (as in .net framework with wsHttpsBinding) then that would be faster (at least for me) since VS would generate all the code for me :) But I have thought of this as a solution too if I want to go the .net core way. Thanks for your input. – Björn Sep 04 '20 at 05:52