为什么 .net 核心不支持 TransportWithMessageCredential? [英] Why TransportWithMessageCredential is not supported in .net core?
问题描述
我正在尝试在 .net core 中使用 SOAP 服务
I am trying to consume a SOAP Service in .net core
我想将安全模式的基本 httpbinding 设置为 TransportWithMessageCredential
I want to set the basic httpbinding with security mode as TransportWithMessageCredential
和 clientcredentialType 作为证书
and clientcredentialType as Certificate
但我收到一个错误
绑定安全属性securityMode"的上下文不支持值TransportWithMessageCredential".
The value 'TransportWithMessageCredential' is not supported in this context for the binding security property 'securityMode'.
代码如下
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?
[我能够在 .net 框架中实现这一点,但不能在 .net 核心中实现]
[I am able to achieve this in .net framework but not in .net core]
推荐答案
添加服务引用后只需编辑 .csproj 文件并将这些依赖项从 4.4.* 指向 4.6.*
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>
并添加这个
binding.Security.Mode = System.ServiceModel.BasicHttpSecurityMode.TransportWithMessageCredential;
binding.Security.Message.ClientCredentialType = BasicHttpMessageCredentialType.UserName;
这篇关于为什么 .net 核心不支持 TransportWithMessageCredential?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!