soap表头的问题
现在不是很懂关于表头的情况.....
看了一个实例之后,自己写了一个测试的...但是还是不怎么明白...
希望大家能够指点....
namespace WebServiceTest
{
public class UserCheck:SoapHeader
{
public UserCheck()
{
}
public bool Check()
{
SqlConnection con=new SqlConnection(System.Configuration.ConfigurationSettings.AppSettings["sql"].ToString());
SqlDataAdapter da=new SqlDataAdapter("select count(*) from Logon where Uid='hz' and Pwd='123123' ",con);
DataSet ds=new DataSet();
da.Fill(ds,"test");
if (ds.Tables[0].Rows.Count>=1)
return true;
else
return false;
}
}
[WebService
(
Namespace="SoapHeaderTest",
Description="通过SOAP Header,我们可以简单的实现权限控制",
Name="SoapHeaderTest"
)]
public class SoapHeaderTest : System.Web.Services.WebService
{
public SoapHeaderTest()
{
InitializeComponent();
}
#region 组件设计器生成的代码
//Web 服务设计器所必需的
private IContainer components = null;
/// <summary>
/// 设计器支持所需的方法 - 不要使用代码编辑器修改
/// 此方法的内容。
/// </summary>
private void InitializeComponent()
{
}
/// <summary>
/// 清理所有正在使用的资源。
/// </summary>
protected override void Dispose( bool disposing )
{
if(disposing && components != null)
{
components.Dispose();
}
base.Dispose(disposing);
}
#endregion
public UserCheck uschck=new UserCheck();
//需要Soap Header验证的方法前面添加如下
[SoapHeader("uschck")]
[WebMethod (Description="SoapHeaderTest类中ReturnBool方法")]
public bool ReturnBool()
{
return uschck.Check();
}
}
}
1---why 验证要写在表头中???有什么好处????
2---在调用的时候可以如下吗?
lud.SoapHeaderTest soapheader=new test_Web.lud.SoapHeaderTest();
if (soapheader.BeginReturnBool())
Response.Write("<script language=javascript>alert('你通过了验证');</script>");
else
Response.Write("<script language=javascript>alert('你没有通过验证');</script>");
总是提示:
soapheader.BeginReturnBool 没有获得参数0....