using System;
using System.Web.Services;
using System.Web.Services.Protocols;
//请注意此命名空间必须有别于代理动态连接库上的命名空间。
//否则,将产生诸如多处定义AuthHeader这样的错误。
namespace SoapHeadersCS
{
//由SoapHeader扩展而来的AuthHeader类
public class AuthHeaderCS : SoapHeader
{
public string Username;
public string Password;
}
//[WebService(Description="用于演示SOAP头文件用法的简单示例")]
public class HeaderService
{
public AuthHeaderCS sHeader;
[WebMethod(Description = "此方法要求有调用方自定义设置的soap头文件")]
[SoapHeader("sHeader")]
public string SecureMethod()
{
if (sHeader == null)
return "ERROR:你不是VIP用户!";
string usr = sHeader.Username;
string pwd = sHeader.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;
}
}
}
WebService webservice = new WebService(); AuthHeaderCS auth = new AuthHeaderCS(); auth.Username = "vip"; auth.Password = "vippw"; webservice.AuthHeaderCSValue = auth; textBox1.Text = webservice.SecureMethod();
机械节能产品生产企业官网模板...
大气智能家居家具装修装饰类企业通用网站模板...
礼品公司网站模板
宽屏简约大气婚纱摄影影楼模板...
蓝白WAP手机综合医院类整站源码(独立后台)...苏ICP备2024110244号-2 苏公网安备32050702011978号 增值电信业务经营许可证编号:苏B2-20251499 | Copyright 2018 - 2025 源码网商城 (www.ymwmall.com) 版权所有