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