2015-10-20 26 views
1

我正在使用2010 SharePoint列表web服务来返回内容类型,它是通过c#应用程序的字段。图书馆是一个网页,其语言设置为威尔士语,但使用英语的另一种语言。这意味着如果浏览器中的Internet选项设置为英文,则该库显示为英文。 我已经能够为使用客户端对象所做的请求设置Accepts-Language标头,但尚未能为Web服务执行此操作。设置请求标头SharePoint网络服务

是否有可能通过SharePoint Web Services发出的请求上看到标题,如果是这样,如何实现?

回答

1

在ASMX Web服务的情况下,你可以考虑使用以下方法。 SoapHttpClientProtocol Class包含GetWebRequest Method,可用于指定自定义标头。

一旦生成代理类,创建一个从它派生的类和设置自定义首部,如下所示:

public class ListsEx : Lists 
{ 
    protected override WebRequest GetWebRequest(Uri uri) 
    { 
     var request = base.GetWebRequest(uri); 
     //Add the Accept-Language header (for Danish) in the request. 
     request.Headers.Add("Accept-Language:da"); 
     return request; 
    } 
} 

其中Lists是生成的代理类的名称。

使用

using (var client = new ListsEx()) 
{ 
     client.Url = webUri + "/_vti_bin/Lists.asmx"; 
     var reult = client.GetList("Pages"); 
      //... 
} 

结果

enter image description here