Skip to main content


Showing posts from January, 2009

Building SOAP Web-Service Clients in .NET 2.0 - Notes To Self ...

This post is a few notes to help me next time I come across issues building a web-service client ...

Some often used code snippets:

For completeness, init the client proxy:

If you are using WSE: ServiceWse svc = new ServiceWse();

Else:Service svc = new Service();

Set the web-proxy to null, so as to bypass a firewall:

svc.Proxy = new System.Net.WebProxy();

Set the version of SOAP - by default .NET uses 1.1 - incase you need another version, you can do this:

svc.SoapVersion = System.Web.Services.Protocols.SoapProtocolVersion.Soap12;

Code to use if your client needs to use UsernameToken authentication (WSE 3.0):

Microsoft.Web.Services3.Security.Tokens.UsernameToken usrToken = new Microsoft.Web.Services3.Security.Tokens.UsernameToken("UID", "PW", Microsoft.Web.Services3.Security.Tokens.PasswordOption.SendHashed);svc.RequestSoapContext.Security.Tokens.Add(usrToken);

Code to use if you need to bypass an invalid certificate: