这是情况。我有一个webservice(C#2.0),它由(主要)从System.Web.Services.WebService继承的类组成。它包含几个方法,都需要调用一个方法来检查它们是否被授权。在每个web服务调用之前调用某种方法
基本上是这样的(原谅架构,这纯粹是作为示例):
public class ProductService : WebService
{
public AuthHeader AuthenticationHeader;
[WebMethod(Description="Returns true")]
[SoapHeader("AuthenticationHeader")]
public bool MethodWhichReturnsTrue()
{
if(Validate(AuthenticationHeader))
{
throw new SecurityException("Access Denied");
}
return true;
}
[WebMethod(Description="Returns false")]
[SoapHeader("AuthenticationHeader")]
public bool MethodWhichReturnsFalse()
{
if(Validate(AuthenticationHeader))
{
throw new SecurityException("Access Denied");
}
return false;
}
private bool Validate(AuthHeader authHeader)
{
return authHeader.Username == "gooduser" && authHeader.Password == "goodpassword";
}
}
正如你可以看到,Validate
有方法中每个方法调用。我正在寻找一种方法来调用该方法,同时仍然能够以一种理智的方式访问肥皂标题。我查看了global.asax
中的事件,但我认为我不能访问该课程中的标题...我可以吗?
并不像我想象的那么直截了当。现在就试试这个。 – 2008-09-25 08:58:35