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
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" ...
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.
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.
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>
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...
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With