我正在使用傳統的.net 2.0 .asmx Web服務(試圖說服他們切換到WCF,但沒有運氣)。我試圖找到一種方法,不僅可以使用自定義SOAP頭,還可以在每個鏈接中沒有驗證碼的情況下對用戶進行驗證。嘗試重寫SoapHeaderAttribute以將身份驗證添加到屬性
目前,我的web服務看起來是這樣的:
public WebserviceAuthentication currentUser;
[WebMethod(Description="Returns the logged in users credentials")]
[SoapHeader("currentUser")]
public string HelloWorld()
{
var user = AuthenticateUser(currentUser, WebServiceResources.MEDICAREELIGIBILITY_HELLOWORLD);
return string.Format("{0} {1} {2}", user.User.UserName, user.User.ProviderUserKey, user.AccountId);
}
理想情況下,我的代碼更改爲以下:
public WebserviceAuthentication currentUser;
public CustomAuthentication user;
[WebMethod(Description="Returns the logged in users credentials")]
[SoapHeaderAuthentication("currentUser")]
public string HelloWorld()
{
return string.Format("{0} {1} {2}", user.User.UserName, user.User.ProviderUserKey, user.AccountId);
}
SoapHeaderAuthentication會讀取currentUser和確認信息註冊用戶。如果是,則返回自定義用戶對象並填充用戶對象。然後我可以從WebService中訪問用戶對象。
問題是,我無法擴展SoapHeaderAttribute,因爲它是一個密封的類。
可以使用WSE嗎? – 2012-01-03 20:32:22
可能。你有一個例子嗎? – Cyfer13 2012-01-03 20:42:43
不是。我只是知道,在最近的實施中,我能夠更好地控制WSE的頭部。 – 2012-01-04 01:23:46