文章详情

  • 游戏榜单
  • 软件榜单
关闭导航
热搜榜
热门下载
热门标签
php爱好者> php文档>webservice带soapheader验证的实例

webservice带soapheader验证的实例

时间:2010-09-09  来源:爱上狗的狐狸

公司叫我和另一个网站写一个用户接口,如下: 代码 using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Services;
using System.Web.Services.Protocols;
using System.Xml.Linq;

namespace UserLoginTest
{
    /// <summary>
    /// CheckUser 的摘要说明
    /// </summary>
    [WebService(Namespace = "http://tempuri.org/")]
    [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
    [ToolboxItem(false)]
    // 若要允许使用 ASP.NET AJAX 从脚本中调用此 Web 服务,请取消对下行的注释。
    // [System.Web.Script.Services.ScriptService]
    public class CheckUser : System.Web.Services.WebService
    {


        /// <summary>
        /// 不要验证的方法
        /// </summary>
        /// <returns></returns>
        [WebMethod]
        public string HelloWorld()
        {
            return "Hello World";
        }

        public MySoapHeader soapHead = new MySoapHeader();




        /// <summary>
        ///需要验证的方法
        /// </summary>
        /// <param name="UserID"></param>
        /// <param name="UserName"></param>
        /// <param name="msg"></param>
        /// <returns></returns>
        [SoapHeader("soapHead")]
        [WebMethod]
        public bool GetUserInfo(int UserID, string UserName, out string msg)
        {

            string deUserName = EncryptHelper.Decrypt(UserName, "jjjyzy");
            msg = string.Empty;
            if (!soapHead.IsValid(out msg))
            { return false; }

            else
            {
                return checkCount(UserID, deUserName);


            }

        }


        /// <summary>
        /// 查询ID和帐号
        /// </summary>
        private bool checkCount(int userID, string Username)
        {
            string sqlStr = "select table where id=userid and Username= username";


            return true;
        }

    }


    /// <summary>
    /// soaphead验证的方法帐号密码ly(重写一个类)
    /// </summary>
    public class MySoapHeader : System.Web.Services.Protocols.SoapHeader
    {
        public string WsUserName
        { get; set; }
        public string WsPwd
        { get; set; }

        public MySoapHeader()
        {

        }

        public bool IsValid(out string msg)
        {
            return IsValid(WsUserName, WsPwd, out msg);
        }
        private bool IsValid(string wsusername, string wspwd, out string msg)
        {//, out string msg
            msg = string.Empty;
            if (wsusername == "ly" & wspwd == "ly")
            { msg = "您有权调用"; return true; }

            else { msg = "您无权调用"; return false; }
        }

    }
}

 

相关阅读 更多 +
排行榜 更多 +
辰域智控app

辰域智控app

系统工具 下载
网医联盟app

网医联盟app

运动健身 下载
汇丰汇选App

汇丰汇选App

金融理财 下载