asp tutorials, asp.net tutorials, sample code, and Microsoft news from 15Seconds
Data Access  |   Troubleshooting  |   Security  |   Performance  |   ADSI  |   Upload  |   Email  |   Control Building  |   Component Building  |   Forms  |   XML  |   Web Services  |   ASP.NET  |   .NET Features  |   .NET 2.0  |   App Development  |   App Architecture  |   IIS  |   Wireless
 
Pioneering Active Server
 Power Search





Active News
15 Seconds Weekly Newsletter
• Complete Coverage
• Site Updates
• Upcoming Features

More Free Newsletters
Reference
News
Articles
Archive
Writers
Code Samples
Components
Tools
FAQ
Feedback
Books
Links
DL Archives
Community
Messageboard
List Servers
Mailing List
WebHosts
Consultants
Tech Jobs
15 Seconds
Home
Site Map
Press
Legal
Privacy Policy
internet.commerce














internet.com
IT
Developer
Internet News
Small Business
Personal Technology
International

Search internet.com
Advertise
Corporate Info
Newsletters
Tech Jobs
E-mail Offers

HardwareCentral
Compare products, prices, and stores at Hardware Central!

Modifying Web Services Documentation
By Manuj Aggarwal
Rating: 4.1 out of 5
Rate this article


  • email this article to a colleague
  • suggest an article

    Introduction

    .NET has made it easy to write and publish Web services. Just write an .asmx file with one or more public methods, decorate it with a 'WebMethod' attribute, and you are in business. When you load the Web service's .asmx page in a browser, you will see a very helpful documentation page that is automatically generated by ASP.NET. This article shows how to customize this documentation page and hide the associated WSDL file.

    Figure: Our simple Web service

    Some Background

    ASP.NET actually generates this page by picking up a default page template for Web services, which ships with the .NET Framework. You can find this default template in <Windows System Folder>\Microsoft.NET\Framework\<.NET Framework Version>\CONFIG\DefaultWsdlHelpGenerator.aspx.

    This template page uses reflection to pick up information about the Web service. ASP.NET uses this template page and generates the HTML and WSDL parts of the documentation. You can access the WSDL file for the Web service by appending the "WSDL" query string parameter to the .asmx file URL e.g. http://localhost/HelloWorldService.asmx?WSDL.

    Figure: WSDL for our simple Web service

    Hide Web Service Documentation

    This WSDL provides all the information about the Web service. Anyone can consume this WSDL and generate a proxy to talk to the Web service. Now say that you are working on a secure Web service and you would like to hide all the information about the Web service. It is only available to some known clients, which are already aware of the WSDL/schema. You can instruct the ASP.NET runtime not to generate any documentation for the Web service by updating the web.config like this:

    <?xmlversion="1.0"encoding="utf-8"?>

    <configuration>

    <system.web>

                  <!--

                  HIDE THE DOCUMENTATION FOR THE WEB SERVICE

    -->

                  <webServices>       

                         <protocols>         

                               <removename="Documentation"/>        

                         </protocols>   

                  </webServices> 

    </system.web>

    </configuration>

    As soon as you update the web.config, you can neither access the HTML documentation page nor the WSDL for the Web service.

    Figure: Web service without HTML documentation

    Figure: Web Service without WSDL Document

    Customizing the HTML Documentation Page

    So now you know how to get rid of the documentation pages. But what if you only want to remove the WSDL part of documentation and keep the HTML documentation page to give a face to the Web service? Comment out the changes in web.config for now. You will come back to removing the WSDL later. Now is the time to focus on customizing the HTML documentation page.

    You can alter the default page template (DefaultWsdlHelpGenerator.aspx) that ASP.NET uses to generate the default documentation page, but this will affect all the Web services deployed on the Web server. A better choice would be to write your own page. So now create a very simple ASP.NET page called helpPage.aspx and include it in the same solution.

    Figure: Customized help page

    To hook up the custom help ASP.NET page to the Web service, you have to update your web.config file:

    <?xmlversion="1.0"encoding="utf-8"?>

    <configuration>

    <system.web>

                  <!--

                  HOOK UP OUR CUSTOM HELP PAGE WITH OUR WEB SERVICE     

    -->

                  <webServices>       

                         <wsdlHelpGeneratorhref="helpPage.aspx"/>

                  </webServices> 

    </system.web>

    </configuration>

    After modifying the web.config, navigate to the Web service page. You should see the customized help page instead of the default ASP.NET page.

    Figure: Custom page in action

    Now back to switching off the WSDL documentation only. Frankly there is no elegant way to turn off WSDL and leave the HTML documentation alone. So you can simply forbid ASP.NET to serve WSDL pages by trapping the Application_BeginRequest event in the global.acax file.

    protectedvoidApplication_BeginRequest(Objectsender, EventArgse)

    {

    string        requestPath = Request.RawUrl.Trim().ToLower();

    if (requestPath.IndexOf("?wsdl") > 0 || requestPath.IndexOf("?disco") > 0)

    thrownewHttpException(404, string.Empty);

    }

    Now when you try to navigate to the WSDL page you will receive an HTTP 404 error.

    Selectively Turning on WSDL

    This will achieve our goal in production environment, but in case you want to turn on the WSDL file in development environment, you can easily implement any kind of security mechanism to selectively allow access to the WSDL file. For instance you can allow the user to see the WSDL file if he/she is running on the same machine by modifying the code:

    protectedvoidApplication_BeginRequest(Objectsender, EventArgse)

    {

    string        requestPath = Request.RawUrl.Trim().ToLower();

     

    if (!IsLocalRequest())

    {

    if (requestPath.IndexOf("?wsdl") > 0 || requestPath.IndexOf("?disco") > 0)

    thrownewHttpException(404, string.Empty);

           }

    }

    Conclusion

    In this article you learned how to customize the default HTML Web service page and hide the WSDL/schema for a Web service. I hope you find this article useful. Please e-mail me with any comments or question you may have.

    About the Author

    Manuj Aggarwal has been developing applications on Microsoft platforms for more than 6 years. He has extensive experience with B2B and EAI solutions using technologies like SOAP, Web Services, EDI, HL7, etc. He has been working on integration projects using .NET since its beta. He received his MCSD certification in 1998 for VB6 and recently received the MCSD Early Achiever for .NET. He can be reached at manuj@canada.com.

  • Rate This Article
    Not HelpfulMost Helpful
    1 2 3 4 5
    Other Articles
    Jul 7, 2005 - Hosting Indigo Web Services
    In the second article of his series on Indigo web services, Chris Peiris explains how to host an Indigo web service and examines the IIS, self hosting, and Windows Activation Service hosting options. He then provides step-by-step instructions and sample code for an IIS-hosted and self-hosted Indigo web service.
    [Read This Article]  [Top]
    Jun 8, 2005 - Indigo Programming Model
    In the first part of his series on Microsoft Indigo, Chris Peiris examines the basics of SOA, explains how Indigo fits into the picture and the problems it solves. He then introduces Indigo's programming model and finishes by building a sample Indigo web service using the Microsoft .Net Framework 2.0.
    [Read This Article]  [Top]
    Nov 10, 2004 - Business Intelligence with Microsoft SQL Server Reporting Services - Part 3
    Adnan Masood concludes his discussion of Microsoft SQL Server Analysis services and Microsoft SQL Server Reporting services. In the final part, he discusses Reporting Server web services and using custom code in reports.
    [Read This Article]  [Top]
    Jul 8, 2004 - Using IE's Web Service Behavior To Create Rich ASP.NET Applications
    This article explains the features of the IE Web service behavior and shows how to asynchronously communicate with an ASP.NET Web service directly from the client.
    [Read This Article]  [Top]
    Jul 6, 2004 - Using .NET and Excel 2003 To Validate E-Mails
    Calvin Luttrell shows how to validate e-mail addresses stored in Excel 2003 and provides a special function for solving that pesky problem Yahoo! mail servers cause.
    [Read This Article]  [Top]
    Jun 2, 2004 - Kerberos Authentication with Web Services Enhancements 2.0
    Kerberos authentication is the cornerstone of Windows operating system authentication architecture. Web Services Enhancement 2.0 (WSE 2.0) extends Kerberos support to ASP.NET Web services. Chris Peiris explains the support for this new feature in WSE 2.0.
    [Read This Article]  [Top]
    Dec 15, 2003 - Realizing a Service-Oriented Architecture with .NET
    Chip Irek examines the architectural issues and component design issues of building a .NET application in a service-oriented architecture.
    [Read This Article]  [Top]
    Nov 24, 2003 - Consuming Asynchronous Web Services
    Thiru Thangarathinam shows how to use asynchronous Web services, Windows Service applications, server-based timer components and .NET XML API classes to create high-performance, scalable, and flexible applications.
    [Read This Article]  [Top]
    Nov 12, 2003 - Implementing Paging and XSLT Extensions Using XSLT in .NET - Part 2
    Part one showed how to transform XML data into HTML by using an XSL stylesheet from within a .NET application. This part explains how to make use of XSLT Extension objects and invoke a C# class method from an XSL stylesheet.
    [Read This Article]  [Top]
    Nov 5, 2003 - Implementing Paging and XSLT Extensions Using XSLT in .NET - Part 1
    Learn how to transform XML data into HTML by using an XSL stylesheet from within a .NET application, and then implement a paging solution by declaring and supplying paging parameters to the stylesheet.
    [Read This Article]  [Top]
    Mailing List
    Want to receive email when the next article is published? Just Click Here to sign up.

    Support the Active Server Industry



    JupiterOnlineMedia

    internet.comearthweb.comDevx.commediabistro.comGraphics.com

    Search:

    Jupitermedia Corporation has two divisions: Jupiterimages and JupiterOnlineMedia

    Jupitermedia Corporate Info


    Legal Notices, Licensing, Reprints, & Permissions, Privacy Policy.

    Advertise | Newsletters | Tech Jobs | Shopping | E-mail Offers