用于验证身份验证令牌的SOAP Web服务属性
问题描述:
我想创建某种身份验证属性并将其附加到各种OperationContracts。在此属性内部,它将检查身份验证令牌并确保其在OperationContract运行之前仍然有效。用于验证身份验证令牌的SOAP Web服务属性
在.net平台上实现这个功能的最佳方式是什么? wcf是否有任何已经实现这种功能的特殊属性?我所描绘的东西类似于可以附加到MVC控制器的属性,它们将在操作运行之前执行操作。
如果它是相关的,我使用WCF来创建将由客户在支持SOAP各种平台,它不只是WCF客户
这里消费SOAP的Web服务中的一些代码来澄清我尝试要做到:
接口:
[ServiceContract]
public interface IService
{
[OperationContract]
string ValidateUser(string username, string password);
[OperationContract]
string GetDataAndAuthInCode(string authtoken);
[MyAuthorizationAttribute]
[OperationContract]
string GetDataAndAuthWithAttribute(string authtoken);
}
实现:
public class Service : IService
{
public string ValidateUser(string username, string password)
{
if (!Membership.ValidateUser(username, password))
throw new Exception("invalid user...");
else
return GenerateAuthToken(username);
}
public string GetDataAndAuthInCode(string authtoken)
{
if (!IsAuthTokenValid(authtoken))
throw new Exception("Auth token invalid expired");
else
return GetData();
}
public string GetDataAndAuthWithAttribute(string authtoken)
{
return GetData();
}
}
仅供参考,这有没有关系ASMX。 – 2010-11-09 19:42:57