SOAP Web服务用于验证身份验证令牌的属性

时间:2010-11-09 16:58:51

标签: wcf soap

我想创建某种身份验证属性并将其附加到各种OperationContracts。在此属性中,它将检查身份验证令牌,并确保在运行OperationContract之前它仍然有效。

在.net平台上实现此功能的最佳方法是什么? wcf是否具有已经执行此类功能的任何特殊属性?我所描绘的内容类似于您可以附加到MVC控制器的属性,这些属性将在操作运行之前执行操作。

如果它是相关的,我使用WCF来创建SOAP Web服务,这些服务将由支持SOAP的各种平台上的客户端使用..而不仅仅是WCF客户端

这里有一些代码来澄清我正在尝试做的事情:

接口:

[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();
}
}

1 个答案:

答案 0 :(得分:0)

看起来这就是我正在寻找的......“自定义行为”:

http://msdn.microsoft.com/en-us/magazine/cc163302.aspx#S7