2012-03-19 66 views
1

我創建了JavaScript的以下要求:消耗的XMLHTTPRequest頭

this.XmlHttp.setRequestHeader("AgentGUID", AgentGUID); 

我如何使用它拋出C#web服務? 請求得到以下WebService:

[WebService(Namespace = "http://mysite.com/WebServices/Agent", Description = "Some description")] 
public class AgentService : WebService 
{ 

    [WebMethod(Description = "SomeDesc.", MessageName = "LoginRSA")] 
    public LoginResult LoginRSA(string loginId, string password, string tenant) 
    { 
     // Here I want to consume request header 
    } 
} 

回答

2

認爲你必須看看以下屬性。

HttpContext.Current.Request.Headers["AgentGUID"]; 
1

System.Web.HttpContext.Current.Request是從WebService的也接近,所以你可以使用這個:

var agentGUID = System.Web.HttpContext.Current.Request.Headers["AgentGUID"]; 
+0

局部變量應該以小寫字母開頭。 – svick 2012-03-19 09:55:28

+0

@svick,true,編輯 – 2012-03-19 09:57:27

+0

感謝您的回答!我投了+1,但是因爲他是第一個,我把這個複選標記給了BitKFu。 – 2012-03-19 10:14:32

1

你應該能夠使用this.Context.Request訪問當前請求。這包含一個Headers屬性。

[WebMethod(Description = "SomeDesc.", MessageName = "LoginRSA")] 
public LoginResult LoginRSA(string loginId, string password, string tenant) 
{ 
    string agent = this.Context.Request.Headers["AgentGUID"]; 
} 
+0

感謝您的答案!我投了+1,但是因爲他是第一個,我把這個複選標記給了BitKFu。 – 2012-03-19 10:14:40