soap表头的问题

2000lhzh 2000lhzh 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区
现在不是很懂关于表头的情况.....
看了一个实例之后,自己写了一个测试的...但是还是不怎么明白...

希望大家能够指点....

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....
...全文
评论 4
收藏 已收藏
分享
返回顶部
2000lhzh
Web Services 12,164 成员 16,322 内容