Skip to main content

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:

System.Net.ServicePointManager.ServerCertificateValidationCallback = new RemoteCertificateValidationCallback(myCertificateValidation); ... public bool myCertificateValidation(Object sender, X509Certificate cert, X509Chain chain, SslPolicyErrors Errors) { return true; //You should check the cert yourself here }

This all relates back to a couple of previous posts that I have made on this matter:

Error messages when instantiating the generated client proxy, such as:

WCF Service Reference: "The XML element 'BlahResponse' from namespace 'http://namespace' references a method and a type. Change the method's message name using WebMethodAttribute or change the type's root element using the XmlRootAttribute."

.NET 2.0 Web Reference: "Method webServiceClient.Blah can not be reflected."

Can be from any number of issues. However, first port of call should be to pick a function that you are confident works on the web-service (use soapUI to establish this), then comment out the code in Reference.cs (or Reference.vb) for all other web-methods. Retry instantiating the client proxy with only the web-method that works implemented. It could be that you have some web-methods in there that are not properly implemented at the web-server and are causing a bit of chaos in the generated client code.

Error messages in response to a request to the web-service:

In your SOAP envelope response (received from a Java web-service): "Error reading XMLStreamReader."

In this case, check the protocol versions for HTTP and SOAP that your client is using. You will definitely get this message if your SOAP version is not the same as that of the service, and I think the message is similar if the HTTP version is different(?).

Diagnosis tools to use:

Fiddler: for diagnosis of HTTP traffic - picks up incoming and outgoing XML -

soapUI: highly configurable test client for web-services -

SoapExtension class: allows you to capture incoming and outgoing SOAP traffic -


Popular posts from this blog

HOW-TO: Apply a “baseless merge” in Team Foundation Server 2010 (and 2012)

Another purely technical post on TFS...
The scenario We wish to migrate code between branches that do not have a branch/merge relationship, in order to expedite urgent changes being made by a project team, without disrupting on-going BAU development work. Sample branch hierachy/strategy Imagine the following branching strategy in TFS (visible by connecting to TFS via Visual Studio 2010 or 2012):

Essentially you have a "DEV" branch, which has a "QA" branch, which in turn has a "PROD" branch. DEV is the branch that you would be using for BAU development. As a piece of development matures, you move it into QA, where it is tested by your internal QA team. There may be further changes made in DEV that are moved into the QA branch as the QA team pick up issues. Once the QA team are happy with a packaged of changes, they will move them into PROD, which is essentially the hand-over to the customer. The PROD branch represents the software that the customer has.


HOW-TO: Add/edit a field in Team Foundation Server 2012 using Visual Studio 2012

It's been a while since I made a purely technical post...

So, today I wanted to make a change to a Microsoft Team Foundation Server 2012 (TFS2012) instance that I am working with to reflect "Actual" time spent on a task - mainly for reporting purposes, and because I have found in the past that making this minor process adjustment yields a relatively useful metric over the long-term.

I am using the Microsoft Scrum 2.1 Process Template ( for a project that I am working with. So that I don't forget how to do this (again!) I will blog-post the procedure I've used to add this field to the template as a screen-shot-based tutorial, as follows...
Before Assuming you are familiar with the Scrum Process Template (2.1-ish) - open a task and take a look at the "Details" section, as follows:

 This is where I want my "Actual" field to show up.
Get the Power Tools Download and install the latest v…

Eclipse/Android error: "Multiple dex files define [...]"

Wow, I am really going nuts blogging this-evening - 2nd post in less than an hour. 

Anyway this is a particularly nasty error that I keep running into with Eclipse/Android when starting the emulator after I have not run it for a little while. Since I run the risk of permanently forgetting the solution to the problem every time I walk away from my Android project (and thus having to spend a painful hour-or-so digging up the procedure again), I will blog it here, for my benefit, and for the benefit of anyone who may also suffer the same problem.

The gist is that when you start the emulator in debug mode (that is, you hit the button in the following image), you get the following error message come out on the console and a nasty popup telling you nothing more than there is an error with your program and you need to fix it:

[2012-04-06 23:20:57 - Dex Loader] Unable to execute dex: Multiple dex files define Lcom/google/gson/ExclusionStrategy;
[2012-04-06 23:20:57 - SimpleList] Conversion to Dal…