WSDL stands for Web Services Description Language that is an XML language for describing web services. Although you could technically read it by eye and figure out what it’s trying to tell you, it’s not worth the effort. These documents are meant to be read by programs and figured out.
But you’re probably wondering, “Do I have a WSDL?” Actually, you do and you probably didn’t even realize it. For every web service that ASP.NET creates, it also generates the WSDL for you as well. Actually, it’s generated on the fly but that doesn’t really matter to you the programmer as long as it’s there when you need it. If you want to view the WSDL for a web service, type in the address to the web service and then follow that with “?WSDL” which will call the WSDL document. Below is an example of what this looks like.

Using this WSDL document, we’ll use a program that will generate C# code that will allow us to programmatically call C# objects in order to interact with the web services. After that, we’ll compile it into a DLL for our consumption.
First we need to locate the program called WSDL.exe which is a command line executable file from Microsoft. It typically comes with .NET but you can also download it from here.
http://www.epcc.ed.ac.uk/~ogsanet/wsdl/wsdl.exe
So I saved my WSDL file into the folder C:\webservices
I then opened up the command prompt in Windows and I typed in “wsdl http://localhost/Webservices/WebService.asmx?WSDL” and then hit enter.

Now notice the C# file that was created. This file contains all of the code we need to access the web service using only C# by just calling a single object.

It is a C# source code file with all of the code necessary to only have to call the function that is the web service. It’s going to be a global namespace though because we didn’t specify what the namespace should be for the C# file that was generated so in order to specify the namespace, the wsdl command line should look like this.
“wsdl /n:LinewaveWebServices http://localhost/Webservices/Service.asmx?WSDL”
So the namespace for the new C# web service access object is LinewaveWebServices.
Lets also compile this into a DLL while we’re at it. In order to do that, we need to call the .NET compiler. Depending on your version of .NET that you have installed, this isn’t going to be the same path probably but for me, the command looks like this.
cd C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727
csc /t:library /out:C:\webservices\Services.dll C:\webservices\Service.cs
We need to make sure we’re in the directory that has the csc.exe program and once there, we can compile the C# code file and the /out: parameter determines where the output DLL will go which in this case is the origin of the C# file.
I’ve created a bat file to do all of this for me though so that anytime I make an update to my web service, the bat file only needs to be called and it generates my code files and compiles them. So my bat file looks like this.
cd C:\webservices
wsdl /n:LinewaveWebServices http://localhost/Webservices/Service.asmx?WSDL
cd C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727
csc /t:library /out:C:\webservices\Services.dll C:\webservices\Service.cs
Now all that’s left for us to do is to drop that new DLL into our web project as a reference and start using the objects it created. You won’t have to worry about SOAP, XML or any of those things if you’re generating all of the code for your web service this way. All you need to do is just program into the objects like you would any other C# object but the only difference being these are hitting remote locations.
Pretty simple, huh?
Subscribe to
Posts [Atom]