1
我想創建某種身份驗證屬性並將其附加到各種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