.net core中引用webservice,并忽略https证书验证

1.打开vs, 工具-->扩展和更新

下载这个

 

2.

在admin下右键,添加-->connected service

选择wsdl文件路径,或者服务的url,比如https://****

点击go ,Services栏中会显示搜索出来一个服务,

可以在Namespace栏中修改服务引用的名称

 再点击finish就完成了。

 目录下会看到多的文件夹

然后再程序中调用(自己起的服务名NciicServices下找后面带有Client的类就是生成的代理类)

但如果服务访问https可能会有证书问题导致添加服务失败,在windows装上数字证书后才可以成功添加服务,但部署到linux系统上后访问会报异常

System.AggregateException: One or more errors occurred. (An error occurred while sending the request.) ---> System.ServiceModel.CommunicationException: An error occurred while sending the request. ---> System.Net.Http.HttpRequestException: An error occurred while sending the request. ---> System.Net.Http.CurlException: Peer certificate cannot be authenticated with given CA certificates

 

此时在调用服务之前添加如下一段代码即可

这样就跳过证书验证了。

 

posted @ 2017-06-08 15:13  Loftyambit  阅读(1938)  评论(1编辑  收藏  举报