soap表头的问题

2000lhzh 2005-03-23 05:07:30
现在不是很懂关于表头的情况.....
看了一个实例之后,自己写了一个测试的...但是还是不怎么明白...

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

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....
...全文
162 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
2000lhzh 2005-03-25
  • 打赏
  • 举报
回复
楼上的兄弟...我不是很懂..能够说得再清楚一点吗?????

zzyx 2005-03-25
  • 打赏
  • 举报
回复
把if (soapheader.BeginReturnBool())
换乘
if (soapheader.ReturnBool())试试
2000lhzh 2005-03-24
  • 打赏
  • 举报
回复
没有人回答???

自己顶
zzyx 2005-03-24
  • 打赏
  • 举报
回复
BeginReturnBool是异步调用嘛
你得到的返回值不是WebService执行的返回值。
最简单的处理是用ReturnBool调用呀

12,162

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 Web Services
社区管理员
  • Web Services社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧