title: WsHttpBinding on .Net Core
body: <p>I'm migrating a <code>.Net 4.x</code> project to <code>.Net Core 3.1</code>. This project is heavily dependent on <code>SOAP</code> web services. As <code>.Net Core</code> does not support configuration based WCF service consumption, I call the service by code. Current project uses <code>ws2007HttpBinding</code> binding.</p>
  <p>My problem is that <code>ws2007HttpBinding</code> does not exists officially in <code>.Net Core</code>. I have no option other than <code>HttpBinding</code>, <code>HttpsBinding</code> and <code>CustomBinding</code>. I have tried all of them with different configurations, but each time encounter an error. Sometime it complaint about <code>https</code> scheme (service which I am using is <code>https</code>), sometimes it says it has expected <code>text/xml</code> but has not seen it, and it maybe a result of different SOAP protocls each side is using, and sometimes I just get timeout error.</p>
  <p>In my last try, I installed <a href="https://www.nuget.org/packages/Microsoft.NETCore.Platforms/" rel="nofollow noreferrer">Microsoft.NETCore.Platforms 3.1.2</a> and <a href="https://www.nuget.org/packages/System.ServiceModel.Http/" rel="nofollow noreferrer">System.ServiceModel.Http 4.7.0</a> and later 4.8.0-preview3.20412.3. The latter has implenetations of both <a href="https://docs.microsoft.com/en-us/dotnet/api/system.servicemodel.wshttpbinding?view=dotnet-plat-ext-3.1" rel="nofollow noreferrer"><code>WsHttpBinding</code></a> and <a href="https://docs.microsoft.com/en-us/dotnet/api/system.servicemodel.ws2007httpbinding?view=netframework-4.8" rel="nofollow noreferrer"><code>Ws2007HttpBinding</code></a>. But, neither worked. This time I got error:</p>
  <p>System.NotSupportedException: Specified method is not supported.</p>
  <p>Any solution or suggestion is highly appreciated.</p>
  <p>Here it is the stack trace and parts of the code:</p>
  <pre><code>System.AggregateException: One or more errors occurred. (Specified method is not supported.)
   ---&gt; System.NotSupportedException: Specified method is not supported.
     at System.ServiceModel.MessageSecurityOverHttp.CreateSecurityBindingElement(Boolean isSecureTransportMode, Boolean isReliableSession, MessageSecurityVersion version)
     at System.ServiceModel.WSHttpSecurity.CreateMessageSecurity(Boolean isReliableSessionEnabled, MessageSecurityVersion version)
     at System.ServiceModel.WSHttpBinding.CreateMessageSecurity()
     at System.ServiceModel.WSHttpBindingBase.CreateBindingElements()
     at System.ServiceModel.WSHttpBinding.CreateBindingElements()
     at System.ServiceModel.Channels.Binding.EnsureInvariants(String contractName)
     at System.ServiceModel.Description.ServiceEndpoint.EnsureInvariants()
     at System.ServiceModel.Channels.ServiceChannelFactory.BuildChannelFactory(ServiceEndpoint serviceEndpoint, Boolean useActiveAutoClose)
     at System.ServiceModel.ChannelFactory.CreateFactory()
     at System.ServiceModel.ChannelFactory.OnOpening()
     at System.ServiceModel.Channels.CommunicationObject.System.ServiceModel.IAsyncCommunicationObject.OpenAsync(TimeSpan timeout)
     at System.ServiceModel.Channels.CommunicationObject.OpenAsyncInternal(TimeSpan timeout)
     at System.Runtime.TaskHelpers.WaitForCompletion(Task task)
     at System.ServiceModel.Channels.CommunicationObject.Open(TimeSpan timeout)
     at System.ServiceModel.Channels.CommunicationObject.Open()
     at System.ServiceModel.ChannelFactory.EnsureOpened()
     at System.ServiceModel.ChannelFactory`1.CreateChannel(EndpointAddress address, Uri via)
     at System.ServiceModel.ChannelFactory`1.CreateChannel()
     at System.ServiceModel.ClientBase`1.CreateChannel()
     at System.ServiceModel.ClientBase`1.CreateChannelInternal()
     at System.ServiceModel.ClientBase`1.get_Channel()
     at client.Inquiry_DataAsync(String NationalCode) in C:\Users\Reference.cs:line 5577
     at class1.&lt;&gt;c__DisplayClass13_0.&lt;Inquiry_Data&gt;b__0() in C:\Users\Code.cs:line 349
     at System.Threading.Tasks.Task`1.InnerInvoke()
     at System.Threading.Tasks.Task.&lt;&gt;c.&lt;.cctor&gt;b__274_0(Object obj)
     at System.Threading.ExecutionContext.RunFromThreadPoolDispatchLoop(Thread threadPoolThread, ExecutionContext executionContext, ContextCallback callback, Object state)
  --- End of stack trace from previous location where exception was thrown ---
     at System.Threading.Tasks.Task.ExecuteWithThreadLocal(Task&amp; currentTaskSlot, Thread threadPoolThread)
     --- End of inner exception stack trace ---
     at System.Threading.Tasks.Task.ThrowIfExceptional(Boolean includeTaskCanceledExceptions)
     at System.Threading.Tasks.Task`1.GetResultCore(Boolean waitCompletionNotification
  </code></pre>
  <p>code:</p>
  <pre><code>        PermissiveCertificatePolicy.Enact(&quot;*&quot;);
  
          var binding = new WSHttpBinding();
  
          binding.Security.Mode = SecurityMode.TransportWithMessageCredential;
          binding.Security.Transport.ClientCredentialType = HttpClientCredentialType.None;
  
          ServiceClient client = new ServiceClient(
              binding, new EndpointAddress(&quot;https://example.com/service.svc&quot;));
          client.ClientCredentials.UserName.UserName = username;
          client.ClientCredentials.UserName.Password = password;
          client.ClientCredentials.ServiceCertificate.SslCertificateAuthentication = new X509ServiceCertificateAuthentication
          {
              CertificateValidationMode = X509CertificateValidationMode.None,
              RevocationMode = X509RevocationMode.NoCheck
          };
  
          _result = Task.Run(() =&gt; client.InquiryDataAsync(&quot;ABC&quot;)).Result;
  </code></pre>