Page 1
Page 2
[update 10/17/2002:- I have added
code to consume the web service using the proxy class as
well as using a WebRequest]
It wasn't so long ago that Robert Levy
and I were talking about .NET, we're both big fans! Anyway
Robert made some comment about it being the Holy Grail of
developing. If this article doesn't make you a believer
then nothing will. Brave words you say - well get comfy
and follow along - you won't believe how easy it is to add
and comsume an XML web service in the Compact Framework.
One of the very coolest things about .NET web services is
that you can literally build a platform agnostic API to
whatever application you want. In fact there is nothing
to stop you building an API to your web site! But first
let's learn to walk before we run headlong into that dark
night by starting with something simple. Suppose that I
want to provide a means for other webmasters to link to
the developer articles on DEVBUZZ. There are many great
technical authors who have contributed to DEVBUZZ and perhaps
they would like to automatically generate links to their
articles.
The DEVBUZZ Author-Article Web Service
What information could authors want?
Well they certainly want the title, description and a URL;
but perhaps they would also like the read counter information?
With that in mind I built a stored procedure that accepts
an email address and returns the appropriate XML from my
article database. You can find the web service here:
http://www.devbuzz.com/class/WebAPI.asmx
This web service exposes a method called
GetAuthorArticles, which requires you to enter an
email address and it returns all the article information
for the specific author. To give it a whirl with my email
address click on the link below:
Popup
window showing the article XML for derek@devbuzz.com
The XML has the following structure:
- <root>
<Article Title="NET Compact Framework - Making the
Switch!"
Date="2002-09-16T09:45:0"
ReadCounter="3574"
URL="http://www.devbuzz.com/content/
zinc_dotnet_compact_framework_switch_pg1.asp"/>
The beauty of the XML web service is
that it returns XML and anyone can access the information
and transform it using XSL, displaying it in their proprietary
format. So regardless of your web server platform software,
Apache, IIS, WebSphere etc. you can call the web service
since it's just an HTTP request, and as such it can pass
through firewalls, proxies etc. Now although you probably
wouldn't have much use for this particular web service on
your Pocket PC, it will serve as a good example for me to
show how to consume a web service from a Pocket PC application.
Adding the web service reference
to the application
Step 1
VS.NET makes it so easy to add a web
service to your application. Right click the References
folder in your project and click on Add Web Reference.

Step 2
Next you will see the Add Web Reference
dialog. Type in:
http://www.devbuzz.com/class/webapi.asmx
And click the Add Reference button.

Next Page