More on working with SOAP proxies

In my last post on authentication and SOAP proxies, I mentioned setting the Credentials property on the wsdl.exe-generated proxy object.  Another way to do it and do other things is to override the GetWebRequest() method.

In the following example, the culture is set in the standard HTTP header to tell the server what culture to use for any formatted data, and the credentials are set directly from some object in the app that holds the credentials.  The advantage of setting the credentials this way is that we don't have to know whether the credentials have changed -- we always get them from the main location before sending each SOAP request.

internal class MyProxy : WsdlExeGeneratedProxy
// Customize the web request.
protected override WebRequest GetWebRequest(Uri uri)
HttpWebRequest request = base.GetWebRequest(uri) as HttpWebRequest;
request.Headers.Add("accept-language", CultureInfo.CurrentUICulture.Name);
request.Credentials = m_state.Credentials;
return request;

internal SomeObject m_state;

If you are using Whidbey Beta 1, check out the article on MSDN about the new SOAP proxy generation options, including generating the proxy assembly at build time (rather than the default of generating and building an assembly at runtime) and how to turn on compression.

Comments (3)

  1. chadbr says:

    Will setting the culture on the way out fix this problem on the way in?


    posted to a newsgroup ages ago…

    Basic scenario:

    -Winforms client calling an web service on Windows XP

    Problem: When I perform an async web service call from a winform client, my Thread.CurrentCulture and Thread.CurrentUICulture are changed from the initiating thread’s culture.

    Some code:

    Set all the Cultures to a different culture:

    static void Main()


    Thread.CurrentThread.CurrentCulture = new CultureInfo("fi-FI");

    Thread.CurrentThread.CurrentUICulture = new CultureInfo("fi-FI");

    Application.CurrentCulture = new CultureInfo("fi-FI");

    Application.Run(new SomeForm());


    Make an Async webservice call:

    IAsyncResult ar = myWebService.BeginSomeWebServiceMethod(new AsyncCallback(MyCallback), "hi");

    Recieve the callback:

    private void GetDatabaseInfoCallback(IAsyncResult ar)


    string retval = myWebService.EndSomeWebServiceMethod(ar);

    //Thread.CurrentThread.CurrentCulture.Name is now "en-US"


    Is this correct? How can I get my callback threads to be in the same culture as the Application thread?

  2. Buck Hodges says:

    If you want the web service telling you the culture in the response, you could have it send it back in a response header and then extract the value from the header. One way to do it would be to override the GetWebRepsonse() methods as shown in

    Beyond that, determining how to do it really depends on what your application is doing and how it is architected.

Skip to main content