本人最近碰到DotNet和DotNetCore调用Https的情况。DotNetCore调用Https的资料特别少,试了两天才试好,分享出来给后面人避坑。用VS生成Webservice代理类的事就不说了额。

DotNetCore片段

BasicHttpBinding bind1 = new BasicHttpBinding();
if (currentFullFilename.ToLower().Contains("https://"))
{//类似浏览器确认证书合法方法的绑定ServicePointManager.ServerCertificateValidationCallback = RemoteCertificateValidationCallback;bind1 = new BasicHttpBinding(BasicHttpSecurityMode.Transport);
}
bind1.ReaderQuotas = new System.Xml.XmlDictionaryReaderQuotas();
bind1.ReaderQuotas.MaxArrayLength = int.MaxValue;
bind1.ReaderQuotas.MaxStringContentLength = int.MaxValue;
bind1.MaxReceivedMessageSize = int.MaxValue;
EndpointAddress endpointAddress = new EndpointAddress(GetFileServiceAddr(currentFullFilename));
UpFileServiceSoapClient client = new UpFileServiceSoapClient(bind1, endpointAddress);
client.ClientCredentials.ServiceCertificate.SslCertificateAuthentication =
new X509ServiceCertificateAuthentication()
{CertificateValidationMode = X509CertificateValidationMode.None,RevocationMode = System.Security.Cryptography.X509Certificates.X509RevocationMode.NoCheck,
};
string ret = client.ReNameAsync(currentFullFilename, newFullFilename).Result.Body.ReNameResult;

DotNet片段

BasicHttpBinding bind1 = new BasicHttpBinding();
if (serverPath.ToLower().Contains("https://"))
{//类似浏览器确认证书合法方法的绑定ServicePointManager.ServerCertificateValidationCallback = RemoteCertificateValidationCallback;bind1 = new BasicHttpBinding(BasicHttpSecurityMode.Transport);
}
bind1.ReaderQuotas = new System.Xml.XmlDictionaryReaderQuotas();
bind1.ReaderQuotas.MaxArrayLength = int.MaxValue;
bind1.ReaderQuotas.MaxStringContentLength = int.MaxValue;
bind1.MaxReceivedMessageSize = int.MaxValue;
EndpointAddress endpointAddress = new EndpointAddress(GetFileServiceAddr(serverPath));
UpFileServiceSoapClient client = new UpFileServiceSoapClient(bind1, endpointAddress);
string ret = client.ReName(serverPath + remotePath + currentFilename, serverPath + remotePath + newFilename);

这里有个坑,如果是DotNetCore用SOAPCore发布的webservice用上面DotNet代码调用没问题,用上面DotNetCore调用的话传的参数长度超过8000多会报MaxStringContentLength超过设置,开始一直以为是客户端调用代码的事,各种设置MaxStringContentLength无效,后面发现是发布方需要设置MaxStringContentLength

所以发布webservice时候应该明确设定最大长度

/// <summary>
/// 绑定终节点
/// </summary>
/// <typeparam name="T"></typeparam>
/// <param name="routes"></param>
/// <param name="path"></param>
/// <returns></returns>
public IEndpointConventionBuilder UseSoapEndpoint<T>(Microsoft.AspNetCore.Routing.IEndpointRouteBuilder routes, string path)
{BasicHttpBinding bind1 = new BasicHttpBinding();bind1.ReaderQuotas = new System.Xml.XmlDictionaryReaderQuotas();bind1.ReaderQuotas.MaxArrayLength = int.MaxValue;bind1.ReaderQuotas.MaxStringContentLength = int.MaxValue;bind1.MaxReceivedMessageSize = int.MaxValue;return routes.UseSoapEndpoint<T>(path, bind1);
}

积极分享,分享人多了就成生态了

DotNetCore调用Https相关推荐

  1. ios调用restful接口_Postman调用https异常解决

    Postman为开发者比较常用的api测试工具,功能强大,支持各种restful接口调试,支持文件上传和文件下载. 这里主要根据项目调用https接口出现以下异常做个简要的操作讲解: 调用接口后pos ...

  2. 【SSL】调用HTTPS://服务遇到错误:unable to find valid certification path to requested target

    前言 OkHttpClient 最近有个需求,需要调用一个https开头的URL服务. 服务方提供了一个demo,但,demo是调用http的服务. 网上找了一大圈,发现盖起来要这样要那样的.都不符合 ...

  3. java webservice ssl_[转贴]Java客户端调用Https Webservice

    标题: Java客户端调用Https Webservice出处地址:http://hi.baidu.com/sunshibing/blog/item/08f873f0d41e67c37931aa84. ...

  4. Spring Boot项目中使用RestTemplate调用https接口出现 unable to find valid certification path to requested target

    问题描述:Spring Boot项目中使用RestTemplate调用https接口出现以下错误: PKIX path building failed: sun.security.provider.c ...

  5. java使用cxf调用https方式的webservice

    推荐尝试hutool工具调用: webservice服务利用hutool工具调用wsdl超简单_XYLANCC的博客-CSDN博客_hutool 调用wsdl 以下内容转载之后亲自测试过,又整理添加了 ...

  6. java调用https的webservice,https的wsdl

    java调webService太正常了... 在调用https的webService的时候几种常用的方法会出现安全错误,很多人说的是在jre里面装证书...那也太郁闷了吧 这里提供一种不用证书的方式 ...

  7. 【实测避坑】SAP PI/PO系统 配置证书调用https地址

    博主内容在此链接原文上修改,避免初次配置https的时候踩到大坑,目前发现知乎,CSDN等相关文章中均未提及,博主踩坑花了2天时间才找到原因,未避免后续人员踩坑,在此文中特别补充. 在原文的基础上进行 ...

  8. 关于JDK1.6调用https握手失败问题

    此博客只是记录了自己在开发过程中遇到的问题以及最后的解决方案,如有侵权请联系我删除! 问题描述: 由于业务需求,需要将http换成https,在测试中出现了一个问题:也就是JDK1.7可以正常请求而J ...

  9. Java调用Https接口:fatal, handshake_failure问题记录

    一. 问题描述 HttpClient调用接口,报错:handling exception: javax.net.ssl.SSLHandshakeException: Received fatal al ...

最新文章

  1. 加载静态文件,父模板的继承和扩展
  2. Python爬虫实战(1):爬取糗事百科段子
  3. Py之pyecharts:python包之数据可视化包pyecharts简介、安装、使用方法之详细攻略
  4. 怎么使图表居中显示_【Excel技巧】制作柱形图图表完美呈现百分比,提升您的报表颜值...
  5. IOC--IOC+AOP--热插拔的系统架构实现演化
  6. 2015计算机类专业课类试卷,2015计算机专业知识试题.doc
  7. CSS3和jQuery实现的自定义美化Checkbox和Radiobox
  8. 函数闭包的方式实现lua面向对象
  9. bzoj3390[Usaco2004 Dec]Bad Cowtractors牛的报复*
  10. 离散数学及其应用(英文版 第7版)及答案
  11. 计算机专业题库,计算机专业综合练习题库(附答案)
  12. php 动态倒计时计数器跳转至另一个页面,JavaScript_基于JavaScript实现网页倒计时自动跳转代码,用JS实现网页上的自动跳转功 - phpStudy...
  13. 网站商务BD(Bussiness Development--商务拓展)
  14. 【Allen方差】计算allen方差
  15. krpano 常用标签
  16. 压缩指定大小的BitMap
  17. Windows Update有用吗
  18. 网络安全与网站安全及计算机安全:如何使用Kali Linux进行MS08-067安全演练
  19. 织梦自动内链(文档关键词功能)无效解决办法
  20. 为什么一般公司面试结束后会说「回去等消息」,而不是直接告诉面试者结果?

热门文章

  1. 《大型网站技术架构原理与解析》第八章 固若金汤:网站的安全架构
  2. Q4收入创新高净亏损却同比扩大121%,网易有道何时盈利上岸
  3. OpenCV-Python实现实时人手跟踪(附源码)
  4. linux查看系统运行时间及启动时间
  5. IT学习,大学不迷茫
  6. 北航计算机系导师,北航计算机学院计算机系统结构导师介绍:钱德沛
  7. JS 获取页面滚动条的高度
  8. JS 获取滚动条到底部得距离
  9. mysql 错误2020_mysqldump: Error 2020: Got packet bigger than ‘max
  10. MATLAB与STK互联1:建立STK场景并保存(补丁)