title: Call Soap 1.2 service from .net core
body: <p>I'm trying to consume a SOAP 1.2 WCF service from .net core 3.1.<br />
  I have a client in .net framework 4 working. It uses wsHttpBinding with security mode TransportWithMessageCredential.</p>
  <p>First I tried to use wsHttpBinding in my .net core client but I got a &quot;Platform not supported&quot; exception. So I switched to BasicHttpsBinding but that led to another exception when I called a function:</p>
  <blockquote>
  <p>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.</p>
  </blockquote>
  <p>From what I found BasicHttpsBinding  is for Soap 1.1 and wsHttpBinding is for Soap 1.2.<br />
  So I tried setting the Soap-version to 1.2 according to <a href="https://stackoverflow.com/a/53336689">https://stackoverflow.com/a/53336689</a> but that gave me another exception:</p>
  <blockquote>
  <p>SocketException: An existing connection was forcibly closed by the remote host.</p>
  </blockquote>
  <p>This is the working config for .net 4 (somewhat abbreviated for readability):</p>
  <pre><code>&lt;bindings&gt;
          &lt;wsHttpBinding&gt;
              &lt;binding name=&quot;ServiceEndpoint&quot; 
                  messageEncoding=&quot;Text&quot; textEncoding=&quot;utf-8&quot;&gt;
                  &lt;readerQuotas maxDepth=&quot;32&quot; maxStringContentLength=&quot;8192&quot; maxArrayLength=&quot;16384&quot;
                      maxBytesPerRead=&quot;4096&quot; maxNameTableCharCount=&quot;16384&quot; /&gt;
                  &lt;reliableSession ordered=&quot;true&quot; inactivityTimeout=&quot;00:10:00&quot;
                      enabled=&quot;false&quot; /&gt;
                  &lt;security mode=&quot;TransportWithMessageCredential&quot;&gt;
                      &lt;transport clientCredentialType=&quot;None&quot; proxyCredentialType=&quot;None&quot;
                          realm=&quot;&quot; /&gt;
                      &lt;message clientCredentialType=&quot;UserName&quot; negotiateServiceCredential=&quot;true&quot;
                          algorithmSuite=&quot;Default&quot; /&gt;
                  &lt;/security&gt;
              &lt;/binding&gt;
          &lt;/wsHttpBinding&gt;
      &lt;/bindings&gt;      
  </code></pre>
  <p>This is my .net core code (not working):</p>
  <pre><code>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(&quot;https://domain/Service.svc&quot;));
  serviceClient.ClientCredentials.UserName.UserName = &quot;usr&quot;;
  serviceClient.ClientCredentials.UserName.Password = &quot;pwd&quot;;
  var units = serviceClient.GetUnitsAsync().Result; // Exception here
  </code></pre>