views:

752

answers:

2

I have a webservice on a remote host that I need to invoke from ASP.NET/C# class. What is the simplest way of calling a method via SOAP, given WSDL url and a method signature?

Given: WSDL url as string(available only at runtime, i.e. variable) Method signature(constant)

Need to: Create a soap client and perform method call.

+2  A: 

See here: http://msdn.microsoft.com/en-us/library/d9w023sx(VS.80).aspx

Its very easy in visual studio - you simply add the web reference url and it generates the proxy stub for you.

rifferte
-1: Don't jump to "Add Web Reference" until he say he's stuck at .NET 2.0 and can't use WCF. Otherwise you may be condemning him to live in the past for no good reason.
John Saunders
The question mentioned "simple". That is the simplest way :)Besides - using WCF is extremely similar - you just use "Add Service Reference" as opposed to add "Web Reference". A good overview is here: http://blog.mstern.at/index.php?/archives/64-Creating-a-WCF-web-service-in-C-using-Visual-Studio-2008.html
rifferte
good article - thank you! Though, what if I WSDL's is only available at runtime?
Alex N.
If two things are just as simple, maybe don't recommend the one with no future, ok?
John Saunders
If the WSDL is not available when you develop your client, then there's something seriously wrong. Maybe the service owners don't understand web services, something like that. The WSDL needs to be available to you, to develop the client.
John Saunders
It is available. During runtime user selects specific webservices from the list. Each service implements given method, but outcome of method call differs.
Alex N.
@Alex N.: I think you are referring to the **Url** of the Web Service being available only at runtime. In that case, after you have created an instance of your web service proxy, just assign the **`.Url`** property of that object to any string you want. You can obtain that string from any location you want (a config or from a web location).
paracycle
+1  A: 

The simplest thing to do is to just use "Add Service Reference" and point to the WSDL. It will generate the proxy classes for you, including a proxy method which should match the method signature you've been given.

See if you find How to Consume a Web Service to be helpful.

John Saunders