mysoapheaders.asmx
来自「这是《ASP.NET编程实作教程》一书中的源文件 如果有此书的朋友不防下载过来参」· ASMX 代码 · 共 55 行
ASMX
55 行
<%@ WebService Language="C#" Class="mySoapHeaders.HeaderService" %>
using System;
using System.Web.Services;
using System.Web.Services.Protocols;
namespace mySoapHeaders {
// 继承SoapHeader类的mySoapHeader类
public class mySoapHeader : SoapHeader {
public string Username;
public string Password;
}
[WebService]
public class HeaderService {
public mySoapHeader myHeader;
[WebMethod]
[SoapHeader("myHeader")]
public string SecureMethod() {
if (myHeader == null)
return "请输入验证信息";
string usr = myHeader.Username;
string pwd = myHeader.Password;
if (AuthenticateUser(usr, pwd)) {
// 验证通过所要完成的操作
return "验证成功: " + usr + "," + pwd;
}
else {
//验证失败要进行的操作
return "验证失败";
}
}
private bool AuthenticateUser(string usr, string pwd) {
//验证过程,用户可以自定义验证的操作,比如从
//数据库中读取用户信息等
if ((usr != null)&&(pwd != null)) {
// 验证操作
return true;
}
return false;
}
}
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?