zoukankan      html  css  js  c++  java
  • winform访问https webservice

    参考:https://www.bbsmax.com/A/x9J21Naez6/

    先执行以下代码,所以密钥验证都返回成功,否则调用https时会提示认证失败。

     ServicePointManager.ServerCertificateValidationCallback = delegate (object sender, X509Certificate certificate, X509Chain chain, SslPolicyErrors errors)
                {
                    // if (errors == SslPolicyErrors.None)
                    //    return true;
                    return true;
                };

    添加web引用,再执行:

      localhost.WebService1 w = new localhost.WebService1();
      w.Url = this.textBox1.Text;    //这可以重写app.config中url地址,使用一个不一样的asmx
     this.textBox2.Text = w.HelloWorld();

    避免用户在浏览器上打开asmx查询接口信息的方法:

    开发时正常处理,发布时在web.config中的 <system.web>节点增加添加以下:

      <webServices>
            <protocols>
              <add name="HttpSoap" />
              <add name="HttpPost" />
              <add name="HttpGet" />
              <add name="Documentation" />
            </protocols>
            <wsdlHelpGenerator href ="webform1.aspx" /> 这个是一个错误页面,请写一个简单的页面
          </webServices>

    经过以上处理,客户端程序调用不受影响,但通过浏览器打开asmx时会跳转到上述的错误页面

  • 相关阅读:
    第六次实训作业
    事件处理程序
    第四次实训作业
    I/O流
    课程总结
    求和计算器
    常用类的课后作业
    窗口实训1
    课后练习----实现窗口的切换
    第五次实训作业继承
  • 原文地址:https://www.cnblogs.com/81/p/14885783.html
Copyright © 2011-2022 走看看