tags:

views:

44

answers:

2

I need to consume a SOAP web service from a C# .Net 4.0 client. I've added the WSDL as a Service Reference in VS 2008 and can now see the XML types as classes so I can construct the SOAP message.

The WSDL Port is defined as an Interface and the two operations defined in the WSDL (UploadMessage and ValidateMessage) are visible methods.

How do you actually use these methods? I thought the Port would be available as a class so you could directly call the methods and that VS would have created the relevant code for sending the SOAP message, but it looks like you have to write code to go in these methods. Is that correct?

I have googled this but can't find a simple example using .Net 4.0 ;-(

+1  A: 

When you add your service using Add Service Reference, you should have a new namespace (which you defined in the Add Service Reference dialog box - bottom left corner).

alt text

Inside that namespace, there ought to be a class called something like (yourservicename)Client.

If you can't find it, open up the Service References node in your Visual Studio Solution Explorer, and find the Show All Files button in the Solution Explorer's little toolbar - click on it to see all files.

alt text

Under your Service Reference, several nodes deep, you should find a file called Reference.cs which contains the code classes generated from your WSDL.

alt text

In that Reference.cs, you should find your client class. This is a regular class, which you can instantiate in your code and call methods on. This will call the web service methods on that remote server you want to connect to.

marc_s
+1  A: 

Typically a Service Reference will create a class called [ServiceName]Client that implements the interface you mentioned.

New it up, then call the operations.

Of far greater importance than getting the client and calling it will be your configuration, which will be dependent on the service. This article will help.

Randolpho
thanks, it's all become a bit clearer now. Does the class always have the same name as the WSDL Port? eg in my case it's called _defaultSoapClient.
Alistair77
@Alistair77: *usually*, but not always. It depends more on the structure of the WSDL than anything else.
Randolpho