大佬教程收集整理的这篇文章主要介绍了如何将具有联合绑定的 wcf 客户端从 .net 框架迁移到 .net 核心?,大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
我正在将 WCF 客户端从 .Net Framework 迁移到 .Net 核心。我正在创建从 ClIEntBase 派生的客户端并使用联合绑定。
这是在 .Net Framework 中工作的绑定创建代码:
private Binding CreateBinding()
{
var issuerBinding = new WShttpBinding(Securitymode.Transport);
issuerBinding.Security.Transport.ClIEntCredentialType = httpClIEntCredentialType.Certificate;
var binding = new WS2007FederationhttpBinding(WSFederationhttpSecuritymode.TransportWithmessageCredential);
binding.Security.message.IssuedKeyType = SecurityKeyType.SymmetricKey;
binding.Security.message.NegotiateserviceCredential = false;
binding.Security.message.EstablishSecurityContext = false;
binding.Security.message.IssuerAddress = new EndpointAddress(this.stsAddress);
binding.Security.message.IssuerBinding = issuerBinding;
return binding
}
这里是.Net core中对应的代码:
private Binding CreateBinding()
{
var issuerBinding = new WShttpBinding(Securitymode.Transport);
issuerBinding.Security.Transport.ClIEntCredentialType = httpClIEntCredentialType.Certificate;
var endpointAddress = new EndpointAddress(this.stsAddress);
var tokenParameters = WSTrustTokenParameters.CreateWS2007FederationTokenParameters(issuerBinding,endpointAddress);
tokenParameters.KeyType = SecurityKeyType.SymmetricKey;
var binding = new WSFederationhttpBinding(tokenParameters);
binding.Security.message.NegotiateserviceCredential = false;
binding.Security.message.EstablishSecurityContext = false;
return binding;
}
不幸的是,.net 核心版本不起作用 - 调用该服务会抛出“http 请求被禁止使用客户端身份验证方案“匿名”。
结果是对sts的请求失败了。 我创建了一个代理来拦截 http 请求,发现对 sts 服务的调用存在以下差异:
<trust:KeyWrapAlgorithm>
http://www.w3.org/2001/04/xmlenc#rsa-oaep-mgf1p
</trust:KeyWrapAlgorithm>
<trust:EncryptWith>
http://www.w3.org/2001/04/xmlenc#aes256-cbc
</trust:EncryptWith>
<trust:SignWith>
http://www.w3.org/2000/09/xmldsig#hmac-sha1
</trust:SignWith>
<trust:CanonicalizationAlgorithm>
http://www.w3.org/2001/10/xml-exc-c14n#
</trust:CanonicalizationAlgorithm>
<trust:EncryptionAlgorithm>
http://www.w3.org/2001/04/xmlenc#aes256-cbc
</trust:EncryptionAlgorithm>
trust:BinarySecret
的 trust:Entropy
元素是不同的。 .net 框架版本包含类型属性 Type="http://docs.oasis-open.org/ws-sx/ws-trust/200512/Nonce"
,该属性在 .net 核心版本中缺失。根据 WS-Trust 文档,默认值为 SymmetricKey。trust:TokenType
元素<trust:TokenType>
http://docs.oasis-open.org/wss/oasis-wss-saml-token-profile-1.1#SAMLV2.0
</trust:TokenType>
如何设置适当的绑定以使其在 .net core 中工作?
Core 不支持 Wshttpbinding,wcf 只支持 BasichttpBinding、CustomBinding、NethttpBinding、NetTcpBinding:
建议你继续使用.net框架或者修改服务端绑定。
,事实证明,.net core WCF 客户端没有随请求发送证书。 .net core 检查证书是否有私钥,如果没有则跳过。 https://github.com/dotnet/corefx/blob/fe7adb2bf92bba926268c2e9f562b11c84932a07/src/Common/src/System/Net/Security/CertificateHelper.cs#L39-L42
if (!cert.HasPrivateKey)
{
conTinue;
}
我从 Azure Key Vault 获取证书,默认情况下它会在没有私钥的情况下返回证书。将其更改为包含私钥解决了问题。
我的 .net framework 应用程序使用相同的方法获取证书(因此它也没有私钥),但它能够从安装了证书的本地机器存储中获取私钥。
以上是大佬教程为你收集整理的如何将具有联合绑定的 wcf 客户端从 .net 框架迁移到 .net 核心?全部内容,希望文章能够帮你解决如何将具有联合绑定的 wcf 客户端从 .net 框架迁移到 .net 核心?所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。