Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why TransportWithMessageCredential is not supported in .net core?

I am trying to consume a SOAP Service in .net core

I want to set the basic httpbinding with security mode as TransportWithMessageCredential

and clientcredentialType as Certificate

but I am getting an error

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

the code looks like this

var client = new SoapCustomClient();

var binding = new BasicHttpBinding(BasicHttpSecurityMode.TransportWithMessageCredential);
binding.Security.Transport.ClientCredentialType = HttpClientCredentialType.Certificate;
client.ClientCredentials.ClientCertificate.Certificate = certCollection[0];

Am I doing some serious mistake here? Any Solution for the same?

[I am able to achieve this in .net framework but not in .net core]

like image 609
sudil ravindran pk Avatar asked Dec 19 '18 13:12

sudil ravindran pk


2 Answers

Just edit the .csproj file after adding the service reference and point these dependencies from 4.4.* to 4.6.*

<ItemGroup> <PackageReference Include="System.ServiceModel.Duplex" Version="4.6.*" /> 
    <PackageReference Include="System.ServiceModel.Http" Version="4.6.*" /> 
    <PackageReference Include="System.ServiceModel.NetTcp" Version="4.6.*" /> 
    <PackageReference Include="System.ServiceModel.Security" Version="4.6.*" /> 
</ItemGroup>

and add this

        binding.Security.Mode = System.ServiceModel.BasicHttpSecurityMode.TransportWithMessageCredential;
        binding.Security.Message.ClientCredentialType = BasicHttpMessageCredentialType.UserName;
like image 56
ali zarei Avatar answered Nov 14 '22 14:11

ali zarei


This problem is solved in newer versions of System.ServiceModel.* packages (4.7.0 worked for me).

See https://github.com/dotnet/wcf/issues/4045#issuecomment-577854822

like image 28
Jarda Avatar answered Nov 14 '22 14:11

Jarda