zoukankan      html  css  js  c++  java
  • 调用 Https WebService 使用程序自动生成代理类

    1 商家提供的WebService接口:  https://ws.nciic.org.cn/nciic_ws/services/NciicServices?wsdl

    2 在浏览器里打开这个地址,会显示一个XML,右击另存为1.wsdl文件

    3 使用vs 的 wsdl.exe工具的来生成代理类

     wsdl.exe的位置  C:Program Files\Microsoft SDKsWindowsv6.0Ainwsdl.exe  (视个人情况而定)

    说明一下:WebService地址 可以是 http或者https的域名,可以是C:1.WSDL的本地文件。 本文就是使用的本地文件(第2步保存的 1.wsdl文件)

    4 使用的Https地址,有时会报:基础连接已经关闭: 未能为 SSL/TLS 安全通道建立信任关系 。这个是因为证书问题。

    在生成的代理类的构造方法里面加入  回调验证,基本上就可以无视证书了

    ///<remarks/>
    public nciicGetCondition()
    {
    this.Url = "http://api.nciic.org.cn/nciic_ws/services/nciicGetCondition";

    //验证服务器证书回调自动验证
    ServicePointManager.ServerCertificateValidationCallback += RemoteCertificateValidate;
    }
    //这个方法 是新加的直接添加进来就行了
    private static bool RemoteCertificateValidate(object sender, X509Certificate cert, X509Chain chain, SslPolicyErrors error)
    {
    // trust any certificate!!!
    System.Console.WriteLine("Warning, trust any certificate");
    //为了通过证书验证,总是返回true
    return true;
    }

    5  调用WebService里面的方法

     string inLicense ="";//授权文件

    NciicServices objText = new NciicServices();

    //读XML文件
    string inConditions = File.ReadAllText(HttpRuntime.AppDomainAppPath + "\XMLFile1.xml");

    string r = objText.nciicCheck(inLicense, inConditions);

    Response.Write(r);

    最后要感谢  苏飞博客

    本文引用:http://www.cnblogs.com/sufei/archive/2010/03/14/https.html

  • 相关阅读:
    javascript基础
    html基础
    css基础
    django-session和cookie
    rest架构
    django-models
    django-templates
    Alignment
    ural 1225.Flags
    ural 1009. K-based Numbers
  • 原文地址:https://www.cnblogs.com/xiaonanmu/p/6877461.html
Copyright © 2011-2022 走看看