views:

692

answers:

4
+5  Q: 

How to use a WSDL

I need to consume a Web Service. They send me the WSDL file. What should I do to add it to my website and start using it as the proxy. ( If I put it on a Virtual Directory it is been discovered, but does it grants me the connection with the real web service?)

+6  A: 

In visual studio.

  • Create or open a project.
  • Right-click project from solution explorer.
  • Select "Add service refernce"
  • Paste the address with WSDL you received.
  • Click OK.

If no errors, you should be able to see the service reference in the object browser and all related methods.

vidalsasoon
<3 Visual Studio.. Yes, it's really that simple :)
cwap
The OP doesn't have an address but a file.
Henk Holterman
type in the path/filename for the WSDL file......
marc_s
The provider of the Web service may have disabled WSDL (security by obscurity), so there is no URL where WSDL can be accessed and then adding a Web reference in VS won't work.However, the provider does want YOU (I mean OP) to know all you need to know about the service contract, that's why they sent the WSDL file. Now the OP needs to generate the proxy code from it, the question is how.
azheglov
By typing in the path to the file. What makes you think that doesn't work?
John Saunders
+7  A: 

I would fire up Visual Studio 2008, create a web project (or console app - doesn't matter), and then right-click on the project and pick "Add Service Reference" from the context menu.

Enter the file path and name into the box and import the WSDL - this will generate a simple, very basic WCF client for you to use. You should find a "YourservicenameClient" class in the generated code which should have methods for each of the defined methods on the WSDL contract.

Instantiate the client and call the methods you want to call - that's all there is!

YourServiceClient client = new YourServiceClient();
client.SayHello("World!");

UPDATE:
if you need to specify the remote URL (not using the one created by default), you can easily do this in the constructor of the proxy client:

YourServiceClient client = new YourServiceClient("configName", "remoteURL");

where "configName" is the name of the endpoint to use (you will use all the settings except the URL), and the "remoteURL" is a string representing the URL to connect to (instead of the one contained in the config).

Marc

marc_s
This works fine. Only one question, if I have the wsdl file on my machine, and I add the reference to this file. When executing the Url it hits is the one hosting the web service, or do I have to especify the Binding and the EndPoint?
jmayor
That's up to you - by default, the code created for the client proxy will have the URL that's contained inside the WSDL - if you need to go to another URL, you need to specify it yourself.
marc_s
+3  A: 

Use WSDL.EXE utility to generate a Web Service proxy from WSDL.

You'll get a long C# source file that contains a class that looks like this:

/// <remarks/>
[System.CodeDom.Compiler.GeneratedCodeAttribute("wsdl", "2.0.50727.42")]
[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.ComponentModel.DesignerCategoryAttribute("code")]
[System.Web.Services.WebServiceBindingAttribute(Name="MyService", Namespace="http://myservice.com/myservice")]
public partial class MyService : System.Web.Services.Protocols.SoapHttpClientProtocol {
    ...
}

In your client-side, Web-service-consuming code:

  1. instantiate MyService.
  2. set its Url property
  3. invoke Web methods
azheglov
This creates an "old-style" ASMX Webservice - those are obsolete - one should use WCF instead nowadays
marc_s
A: 

An alternative cross-platform solution is gSOAP.

titaniumdecoy
He's using C#.
John Saunders