6

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

Jelle Oosterbosch
  • 1,731
  • 15
  • 17
  • Can the WCF client code go into a class library that targets .NET Standard? Then you could call the library from .NET Core. This [SO answer](https://stackoverflow.com/a/45550508/444244) may be relevant. – Boggin Aug 08 '17 at 13:36
  • Are you using the WCF connected services? https://marketplace.visualstudio.com/items?itemName=WCFCORETEAM.VisualStudioWCFConnectedService – Tseng Aug 08 '17 at 14:07
  • The WCF connected services is giving me an error, for the same reason somewhere. Not supported, the error message is just slightly different.. https://github.com/dotnet/wcf/issues/1274 – Jelle Oosterbosch Aug 09 '17 at 06:40
  • @Boggin I generated the service already, it's the connection to that is giving the error. – Jelle Oosterbosch Aug 09 '17 at 06:41
  • someone found a solution? – hugo Aug 29 '17 at 10:26

2 Answers2

13

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>  
Bill
  • 131
  • 1
  • 4
  • 3
    This crucial point saved my life. I was working with 4.4.0 but it never worked. With 4.6.0 version I have solved my problem. Besides, you can use seperate assembly in .net framework and can use in .net core – uzay95 Dec 16 '19 at 08:53
  • Best answer in 2020 – Flacid_Snake Apr 24 '20 at 12:57
2

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...

Jelle Oosterbosch
  • 1,731
  • 15
  • 17