using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Services;
using System.Web.Services.Protocols;
namespace UserCenter
{
public class MySoapHeader :SoapHeader
{
public string UserName
{
get;
set;
}
public string PWD
{
get;
set;
}
}
/// <summary>
/// MyMath 的摘要说明
/// </summary>
[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
[System.ComponentModel.ToolboxItem(false)]
// 若要允许使用 ASP.NET AJAX 从脚本中调用此 Web 服务,请取消对下行的注释。
// [System.Web.Script.Services.ScriptService]
public class MyMath : System.Web.Services.WebService
{
public MySoapHeader sHeader;
[WebMethod]
public string HelloWorld()
{
return "Hello World";
}
[WebMethod]
[SoapHeader("sHeader")]
public string add(int x, int y)
{
if (sHeader.UserName == "test" && sHeader.PWD == "test")
{
return (x + y).ToString();
}
else
{
return null;
}
}
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Services;
using System.Web.Services.Protocols;
namespace XMLClass1.class15.content
{
[AttributeUsage(AttributeTargets.Method)]
public class MyExtensionAttribute : SoapExtensionAttribute
{
int _priority = 1;
public override int Priority
{
get { return _priority; }
set { _priority = value; }
}
public override Type ExtensionType
{
get { return typeof(MyExtension); }
}
}
public class MyExtension : SoapExtension
{
//这个override的方法会被调用四次
//分别是SoapMessageStage BeforeSerialize,AfterSerialize,BeforeDeserialize,AfterDeserialize
public override void ProcessMessage(SoapMessage message)
{
if (message.Stage == SoapMessageStage.AfterDeserialize)//反序列化之后处理
{
bool check = false;
foreach (SoapHeader header in message.Headers)
{
if (header is MySoapHeader)
{
MySoapHeader myHeader = (MySoapHeader)header;
if (myHeader.Name == "admin" || myHeader.PassWord == "admin")
{
check = true;
break;
}
}
}
if (!check)
throw new SoapHeaderException("认证失败", SoapException.ClientFaultCode);
}
}
public override Object GetInitializer(Type type)
{
return GetType();
}
public override Object GetInitializer(LogicalMethodInfo info, SoapExtensionAttribute attribute)
{
return null;
}
public override void Initialize(Object initializer)
{
}
}
public class MySoapHeader : SoapHeader
{
string _name;
string _passWord;
public string Name
{
get { return _name; }
set { _name = value; }
}
public string PassWord
{
get { return _passWord; }
set { _passWord = value; }
}
}
/// <summary>
/// headersoap2 的摘要说明
/// </summary>
[WebService(Namespace = http://tempuri.org/)]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
[System.ComponentModel.ToolboxItem(false)]
// 若要允许使用 ASP.NET AJAX 从脚本中调用此 Web 服务,请取消对下行的注释。
// [System.Web.Script.Services.ScriptService]
public class headersoap2 : System.Web.Services.WebService
{
public MySoapHeader header;
[WebMethod]
[MyExtensionAttribute]
[SoapHeader("header", Direction = SoapHeaderDirection.In)]
public string CheckHeader()
{
//业务逻辑.
return "Something done";
}
}
}
机械节能产品生产企业官网模板...
大气智能家居家具装修装饰类企业通用网站模板...
礼品公司网站模板
宽屏简约大气婚纱摄影影楼模板...
蓝白WAP手机综合医院类整站源码(独立后台)...苏ICP备2024110244号-2 苏公网安备32050702011978号 增值电信业务经营许可证编号:苏B2-20251499 | Copyright 2018 - 2025 源码网商城 (www.ymwmall.com) 版权所有