Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

WCF in .net core (TransportWithMessageCredential)

When I try to create a connection to a WCF client in dotnet core 2.0, I receive an platform unsupported error:

System.PlatformNotSupportedException: 'The value 'TransportWithMessageCredential' is not supported in this context for the binding security property 'securityMode'.'

If I remove the BasicHttpSecurityMode, I receive an argument exception: System.ArgumentException: 'The provided URI scheme 'https' is invalid; expected 'http'.'

Code:

ChannelFactory<BlackBoxContract> factory = null;
BlackBoxContract serviceProxy = null;
Binding binding = null;

binding = new BasicHttpBinding(BasicHttpSecurityMode.TransportWithMessageCredential);

factory = new ChannelFactory<BlackBoxContract>(binding, new EndpointAddress("https:......."));;
serviceProxy = factory.CreateChannel();

Anyone that found a workaround as this might be on the long term roadmap? https://github.com/dotnet/wcf/issues/8

like image 425
Jelle Oosterbosch Avatar asked Aug 08 '17 11:08

Jelle Oosterbosch


People also ask

What is WCF security mode?

Windows Communication Foundation (WCF) security has three common security modes that are found on most predefined bindings: transport, message, and "transport with message credential." Two additional modes are specific to two bindings: the "transport-credential only" mode found on the BasicHttpBinding, and the "Both" ...

What is TransportWithMessageCredential?

TransportWithMessageCredential is a combination of both transport and message security since transport security encrypts and signs the messages as well as authenticates the service to the client and message security is used to authenticate the client to the service.

Is WCF secure?

By default, anyone on the same Windows domain can access WCF services. Because those users have logged on to the network, they are trusted. The messages between a service and a client are encrypted for confidentiality and signed for integrity.


2 Answers

This has been fixed by the latest packages.

  <ItemGroup>
    <PackageReference Include="System.ServiceModel.Duplex" Version="4.6.0" />
    <PackageReference Include="System.ServiceModel.Http" Version="4.6.0" />
    <PackageReference Include="System.ServiceModel.NetTcp" Version="4.6.0" />
    <PackageReference Include="System.ServiceModel.Security" Version="4.6.0" />
  </ItemGroup>  
like image 178
Bill Avatar answered Nov 06 '22 21:11

Bill


Actually found a valid workaround, there is a package you can use for this: https://github.com/gravity00/SimpleSOAPClient

using SimpleSOAPClient;
using SimpleSOAPClient.Handlers;
using SimpleSOAPClient.Helpers;
using SimpleSOAPClient.Models;
using SimpleSOAPClient.Models.Headers;

...

_client = SoapClient.Prepare().WithHandler(new DelegatingSoapHandler());
_client.HttpClient.DefaultRequestHeaders.Clear();
_client.HttpClient.DefaultRequestHeaders.Add("SOAPAction", "Action...");

 var requestEnvelope = SoapEnvelope
     .Prepare()
     .Body(request)
     .WithHeaders(KnownHeader.Oasis.Security.UsernameTokenAndPasswordText(Username, Password));

var responseEnvelope = _client.Send(Url, "CanNotBeEmpty", requestEnvelope);

Got it to work like this, as a charm...

like image 45
Jelle Oosterbosch Avatar answered Nov 06 '22 22:11

Jelle Oosterbosch