Welcome to MSDN Blogs Sign in | Join | Help

ASP.NET Web services test page

Did you know it's possible to customize the test page auto-generated for Web services in ASP.NET?

For example, let's say you wanted to order the WebMethods such that they're displayed in alphabetical order.  You can modify the DefaultWsdlHelpGenerator.aspx page which is used to create that test page (%windir%\Microsoft.NET\Framework\v1.1.4322\CONFIG\DefaultWsdlHelpGenerator.aspx).  ASP.NET gathers up the description information for the requested web service/asmx and passes that data to the help generator page.  You can modify this page however you see fit (or you can tell ASP.NET to look in a different location for the generation page by modifying the machine.config’s system.web/webServices/wsdlHelpGenerator node).

If you look in this file, you’ll see around line 1285:

        Hashtable methodsTable = new Hashtable();
        operationExists = false;
        foreach (ServiceDescription description in serviceDescriptions) {
                foreach (PortType portType in description.PortTypes) {
                        foreach (Operation operation in portType.Operations) {
                                string messageName = operation.Messages.Input.Name;
                                if (messageName == null || messageName.Length == 0) messageName = operation.Name;
                                if (messageName == operationName)  operationExists = true;
                                if (messageName == null) messageName = String.Empty;
                                methodsTable[messageName] = operation;
                        }
                }
        }
        MethodList.DataSource = methodsTable;

The code is creating a hashtable of all of the methods available in the Web service and is then binding the repeater you see on the test page that lists all of the methods to this hashtable.  This sheds light one why the methods appear to be in no particular order on the test page: the code is enumerating a Hashtable rather than an ordered list, so the ordering is at the mercy of the hash values generated for messageName and thus the buckets into which the operations are placed.

To get the methods listed in alphabetical order, all we need to do is make a one line change, from:
        Hashtable methodsTable = new Hashtable();
to
        SortedList methodsTable = new SortedList();

Instead of being placed into a Hashtable, the operations will all be placed into the SortedList, indexed by messageName.  When MethodList is bound to methodsTable (which we would probably also want to rename just for clarity's sake), methodsTable will be enumerated in alphabetical order (thanks to SortedListEnumerator), and thus the methods listed on the test page will be in alphabetical order.

This is, of course, just one simple change you can make to the DefaultWsdlHelpGenerator.aspx page.  The possibilities are limitless :)

Published Wednesday, March 10, 2004 11:50 AM by toub
Filed under:

Comment Notification

If you would like to receive an email when updates are made to this post, please register here

Subscribe to this post's comments using RSS

Comments

Wednesday, March 10, 2004 3:59 PM by Michael Larionov

# re: ASP.NET Web services test page

No, I did not know! This is pretty cool.

The thing which drives me nuts is that the text field in the page is not multiline. So I cannot put a big block of multiline text as a web method parameter. So now editing the page I can change the <input type="text"> to <textarea>. I wonder if someone already done that.

Thanks!
Wednesday, March 10, 2004 10:38 PM by Enjoy Every Sandwich

# Take Outs for 10 March 2004

You have been Taken Out! Thanks for the good post.
Thursday, July 01, 2004 8:00 PM by Volo

# re: ASP.NET Web services test page

Thx for the idea. It's very useful! :)
Other suggestion is to change the code to hide methods that you don't want to publish by using naming conventions.
Friday, May 13, 2005 11:17 PM by Brad Greer

# re: ASP.NET Web services test page

Great! Just the solution I needed to automatically send the XML results from the test page to another web page for viewing with a generic XSLT stylesheet.
Wednesday, May 24, 2006 1:39 PM by Mark Dostie

# re: ASP.NET Web services test page

Awsome!  That's what I needed: textarea and sorted list...
Sunday, January 14, 2007 4:38 PM by Reflective Perspective » links for 2007-01-13

# Reflective Perspective &raquo; links for 2007-01-13

Friday, February 16, 2007 2:21 PM by Sam

# re: ASP.NET Web services test page

Hi,

My test page form URL always comes up wrong and I don't know why? The form action always has a port number appended and the http does not have an "s" appended (https:) even though the server has SSL.

Any idea?

Saturday, October 06, 2007 2:42 PM by Angelo Bestetti

# re: ASP.NET Web services test page

What about if we are hosting in some other place that we cannot access this file? Is there another way arround?

It´s the same for .net 2.0?

Wednesday, January 16, 2008 7:25 AM by Maurício Eduardo Hernaski

# re: ASP.NET Web services test page

I am Brazilian and find solution just here!!

Its working!

Thanks!!!!!

Tuesday, February 05, 2008 5:21 PM by Anu Pareek

# re: ASP.NET Web services test page

I am using the Request and Response messages generated by the Web Services Test page to create documentation for our web services. However, I find that any public properties in base classes are not picked up in the sample messages. For example, Class1 extends Class2. Class1 contains property1 and Class2 contains Property2. For a web service method that returns Class1, the sample Response only contains property1 and not property2.

Can anyone suggest what changes can need to be made to the DefaultWsdlHelpGenerator.aspx to also pick up the public properties from the base class in the sample request/response messages?

Thanks.

Thursday, May 29, 2008 8:57 AM by Rospy

# re: ASP.NET Web services test page

that totally saved my ass!!!! thanx

Tuesday, July 22, 2008 3:15 PM by Lorie

# re: ASP.NET Web services test page

In framework 2.0  DefaultWsdlHelpGenerator.aspx Line 1418 it already has the following code:        

SortedList methodsTable = new SortedList(StringComparer.Ordinal);

I added webmethod descriptions, but I am still unsure how my web services are being sorted.  It isn’t by function, description or webmethod.  Do you have any suggestions?  Thank you

Wednesday, November 12, 2008 1:41 AM by Ketan

# re: ASP.NET Web services test page

How to Check Whether Web Service is Running or Not on Some Button Click Events.

http://dotnet-magic.blogspot.com/

# Stephen Toub ASP NET Web services test page | Shed Kits

# Stephen Toub ASP NET Web services test page | pool toys

# Stephen Toub ASP NET Web services test page | garden decor

Leave a Comment

(required) 
required 
(required) 

  
Enter Code Here: Required
 
Page view tracker