简体   繁体   中英

Set Request Header SharePoint web service

I am using the 2010 SharePoint Lists web service to return a Content Type and it's fields through ac# application. The Library is in a web whose language is set to welsh, but with an alternate language of english set. This means if the internet options in the browser are set to english, the library displays in English. I have been able to set the Accepts-Language header for requests made using the client object but have not been able to do so for the web service.

Is it possible to see a header on requests made through the SharePoint Web Services, and if so, how?

In case of ASMX web services you could consider the following approach. SoapHttpClientProtocol Class contains GetWebRequest Method that could be used for specifying a custom headers.

Once the proxy class is generated, create a class that derives from it and set custom header as shown below:

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;
    }
}

where Lists is the name of generated proxy class.

Usage

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

Result

在此处输入图片说明

I don't know what type of web services you use. In case of WCF services, you can use: How to add a custom HTTP header to every WCF call? In case of ASMX web services: Adding SOAP headers to ASMX service requests .

In both cases use Accept-Language header like "Accept-Language:en"

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM