zoukankan      html  css  js  c++  java
  • 服务篇:我的第一WebService应用

    一、我的第一个Webservice应用

    1.新建一个空项目

    2.添加新项,加入asmx,并再浏览器浏览

    3.添加一个aspx网页

    4.右键引用→添加服务引用→高级→添加Web引用,输入再浏览器浏览的asmx地址→添加引用。

    5.再aspx网页加载时:

    localhost.WebService1 ws = new localhost.WebService1();
    Response.Write(ws.HelloWorld());

    二、Webservice不完全对外公开,如何验证?

     1.再Webservice下定义一个类:

      public class MySoapHeader:SoapHeader
        {
            public string pwd { get; set; }
            public bool Check (string pwd)
            {
                if(pwd=="123")
                {
                    return true;
                }
                else
                {
                    return true;
                }
            }
        }

    2.在基类下加入代码

        public MySoapHeader header;
            [WebMethod]
            [SoapHeader("header")]
            public string HelloWorld()
            {
                if (header.Check(header.pwd))
                {
                    return "Hello World";
                }
                else
                {
                    return "你没有权限调用";
                }
                #endregion
            }

    3.aspx页面加载时

    localhost.WebService1 ws = new localhost.WebService1();
    localhost.MySoapHeader header=new localhost.MySoapHeader();
    header.pwd = "123";
    ws.MySoapHeaderValue = header;
    Response.Write(ws.HelloWorld());
  • 相关阅读:
    groovy集合
    groovy函数、字符串、循环
    groovy运行程序和类型推断
    常见IT英语短语一
    常见IT英语单词
    认识Groovy
    maven入门
    springboot之内嵌tomcat修改端口号
    springboot手动配置数据源:
    img与父元素的间隙解决
  • 原文地址:https://www.cnblogs.com/yinsheng/p/5688970.html
Copyright © 2011-2022 走看看