Making a WSDL Using Visual Studio

I recently figured out how to use MS Visual Studio to generate a WSDL to use for some web service methods I planned to write in Java. It was very easy and painless. A month or so later, I wanted to generate a new WSDL and I drew a complete blank on the “easy procedure”. So this time I’m writing it down.

Background: The web services will provide an alternate method of interacting with a book database application. The page below shows the information I’m collecting on each book.

website sample page

Procedure: Start up Visual Studio and create a new project. Select ASP.NET Web Service Application. Note: you’ll need something better than the free MS Visual Studio Express because it doesn’t support web services.

This next step is quite optional. From screen shot of the book database you can see that I will be transferring a list of data items about each book. So following good object-oriented techniques, I’m making a class (really a data bean) to bundle these together.

Service1.asmx.cs was created automatically by Visual Studio when the project was created. Here’s what it originally looked like. Note that any method that should be exposed as a webservice is annotated with [WebMethod] and that Studio has written a hello world one for you.

After editing, the Service1.asmx.cs now looks like this. I tried to change Service1 something more appropriate but doing a simple rename through the Solution Explorer is not enough. So I’ve left it unchanged. I updated the namespace. And I’ve added create, read, update, delete (CRUD) methods, along with search and a few others.

As much as possible I’m passing databeans or arrays of databeans. For some reason, Studio won’t let you use Hashtable as a return type so I had to create my own simple minded Pair class.

Now we are really ready to get results. Choose Debug -> Start Debugging.

Studio launches IE and displays this page with the available web service methods. Note: This is the part that doesn’t work if you try to change Service1 to something else and just rename the .asmx.cs file.

Click on the Service Description link to see the WSDL. Save this and you are done!

Advertisements

~ by mlbiss on June 14, 2008.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

 
%d bloggers like this: