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.Credentials = m_state.Credentials;
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.