2012-03-19 65 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