Contents

Introduction

This project shows how to extend the ASP.NET XML control and the way to use it to call a web service.
The Web Service used is sending back the latest article posted on CodeProject. The XML control
delivered by Microsoft does not permit to access distant server to get the XML document. Adding this
possibility to the control add new horizon to it. Most of Web Services may be called using HTPP
GET, so with this new control you will be able to get information from them. The XML document
returned by the Web Service will be still processed using XSLT like for the original control.

Extend the control

Using Visual Studio .NET create a new C# 'ASP.NET Web Application' project, call it
AspXmlDemo. When it is created add to the solution a new C# 'Web Control Library' project,
called WebControlXml.
After project's creation Visual Studio .NET presents the generated class. By default, Visual
Studio .NET creates a class inheriting from System.Web.UI.WebControls.WebControl.
You need to change it to System.Web.UI.WebControls.Xml to inherit from the ASP:XML
control.

Then change the class name from WebCustomControl1 to XmlEx. At the same time change the class
attribute to [ToolboxData("<{0}:XmlEx runat=server></{0}:XmlEx>")].
Finally add the namespace attribute: [assembly:TagPrefix("WebControlXml","XmlEx")].

The property get is simple but the property set need some explanations. The parameter value
is assigned to the private local variable. Then we created a WebRequest object
that permits to read the document giving it URL. The response, in fact the XML document, is
downloaded and assigned to the parent variable from System.Web.UI.WebControls.Xml
class. Now that we have the code needed to get and set the URL to the property of the class, it
would be good to be able to set the value directly from the IDE. To achieve it you need to add
the attribute on the DocumentUrl property: [Category("Behavior"), DefaultValue("")].

Then add to WebControlXml project a reference to the .NET assembly 'System.Xml.dll'.
We do not use the Render method. So we delete it. Save and compile.

Using the extended control

For the moment the ASP.NET application is empty so if you run the project with CTRL+F5 you get an empty
page.

Open the file WebForm1.aspx from the AspXmlDemo project. Right click in the Toolbox, menu opens,
click on Customize Toolbox. Click on the .NET Framework Components tab in the dialog that opens,
then on the browse button. Enter the path to the assembly 'WebControlXml.dll'. Click OK. The XmlEx
control is added to the Toolbox.

Drag and drop the XmlEx
control on your ASP.NET page WebForm.aspx. Browsing the property of
the control you remark that the property DocumentUrl is added.

We will use this property to get the latest ten article summaries from
CodeProject website.

Run the application with CTRL+F5. You get an Internet Explorer window with a list of information.
The Web Service called returns the latest ten article summaries from CodeProject as a XML stream. We
did not specify any XSLT file so the control just output to Internet Explorer the XML file.

Add a new XSLT element to the AspXmlDemo project and name it 'codeproject.xslt'. Then modify it to
get :

Save the file. Then modify to 'codeproject.xlt' the 'TransformSource' property of the XmlEx control
on the WebForm1.apsx page.

Run the application with CTRL+F5. You get the same information then before but with a better
formatting (sorry but I am not a WebDesigner ;).

Conclusion

We have seen that with some lines of C# code we considerably extended the possibilities offered by
the ASP:XML control. This little extension opens new doors to the content representation on the
Web by making it able to call Web Services. It also permits Web Designer to use Web Services without
knowing all the plumbing. In fact for the Web Designer, the important thing to know is the URL to
get the information and it structure. After that it needs to display them nicely.

Known Issues

None.

Version

Version
1.00

15 July 2002
First release.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.