解决Azure 消息队列ServiceBus提示证书不信任无权限的问题

笔者在C# 消息队列-Microsoft Azure service bus 服务总线中使用Azure消息队列,最近偶尔会遇到请求数据不入队列的问题,查找日志,问题如下:

异常:X.509 certificate CN=servicebus.chinacloudapi.cn, O=Shanghai Blue Cloud Technology Co. Ltd, L=Shanghai, S=Shanghai, C=CN is not in the trusted people store. 
The X.509 certificate CN=servicebus.chinacloudapi.cn, O=Shanghai Blue Cloud Technology Co. Ltd, L=Shanghai, S=Shanghai, C=CN chain building failed.
The certificate that was used has a trust chain that cannot be verified. Replace the certificate or change the certificateValidationMode.
A certificate chain could not be built to a trusted root authority.

问题显示使用的证书有一个无法验证的信任链。更换证书或改变certificatevalidationmode。无法将证书链构建到受信任的根权限。

问题出现是因为我在创建连接时没有对ConnectivityMode 做预先设置

如果代码中不对 ConnectivityMode 做预先设置,service bus 客户端( web 应用)默认使用了 AutoDetect 模式 连接 service bus 服务。 AutoDetect 会优先使用 TCP 连接模式。由于 TCP 连接模式也是加密的,所以客户端需要首先验证 service bus 服务器证书 CN = servicebus.chinacloudapi.cn 的有效性,证书链信息在 SSL 协议的 server hello 消息中返回。

如果证书链中的某些中间证书没有安装在 web 应用实例上,web 应用需要发起额外的请求到 CA 服务器上下载中间证书并安装。

修改代码如下:

//最好设置连接模式为Https,默认是Tcp。如果是Tcp的话,放到云端WEB应用上会报错
 ServiceBusEnvironment.SystemConnectivity.Mode = ConnectivityMode.Https;
//创建连接
var client = QueueClient.CreateFromConnectionString(connectionString, queueName);

 

转载于:https://www.cnblogs.com/xuwendong/p/7844449.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值