Feature
Publishing .NET Web Services Using SQL Anywhere 10.0.1
Take a database and create a mini version of an "Amazon-like" item lookup
Apr. 4, 2008 11:00 AM
Creating a Web Services Client in Visual Studio
To
test our Web Service, we're going to write a simple client in Visual
Studio. To get things started, create a new C# Windows application.
This can be done by going to File->New->Project and selecting
Windows Application. In the Solution Explorer for this project (usually
shown on the right), right-click on references and you'll have the
option of adding a new Web Reference. Select this and you'll be
presented with the screen shown in Figure 18.
Here you must specify the location of the WSDL. Building on what we've
already done, the address you want to type in is
http://localhost:8080/ItemLookupWSDL. Type this in and click on the Go
button. Visual Studio should find your OurAmazonItemLookup method we
defined earlier in this exercise. Click on the Add Reference button to
add it to your project.
Now that we have a reference to our
service, we'll need to write some code to go about using it. But first
we'll have to set up some GUI elements. In the toolbox (usually shown
on the left) drag four label controls onto your form. Name them
labelItemID, labelTitle, labelAuthor, and labelManufacter. Next add a
text box and name it textBoxItemID. Finally add a button. Your finished
layout should look something like Figure 19.
Now that we have our GUI designed, we can write some code to make our
call to the OurAmazonIItemLookup method. Copy the code in Listing 3
to the clicked event of your form's button. If you study this code,
you'll notice that we're getting a reference to our Web Service and
then making a call by passing it the value the user typed in the text
box. Finally, we use the result set to assign the text property of the
respective label controls. Note: error checking has been omitted for
clarity.
The Finished Product
To use our Web Services
client simply type in a UPC corresponding to an item that you've
already entered in your SQL Anywhere database, click the OK button and
through the magic of SQL Anywhere Web Services your title information
is returned to the client. The finished product is shown in Figure 20.
Conclusion
Building your own "Amazon-like"
ItemLookup Web Services is a piece of cake when you use SQL Anywhere's
Sybase Central wizard to create them. Moreover, consuming them in
Visual Studio is just as easy. Take a few minutes to familiarize
yourself with these powerful development tools and you too will be
publishing and consuming Web Services in no time!
References
- SQL Anywhere Documentation www.ianywhere.com/developer/product_manuals/sqlanywhere.
- SQL Anywhere Developer Edition http://eshop.sybase.com/eshop/try_buy.
- Visual C# and Visual Studio IDE http://msdn2.microsoft.com/en-us/vcsharp/aa336807.aspx.
- Inside SOAP www.xml.com/pub/a/2000/02/09/feature/index.html.
About Deanne M. ChanceMs. Chance graduated in 1996 with a degree in computer science from the University of Illinois. She has been a frequent contributor to the PowerBuilder Developer's Journal and gave a key presentation at Sybase TechWave 2005 entitled "A Real-Time Physical Inventory Solution Using PocketBuilder ASA and a WiFi Connection." She has held several engineering positions, starting a career at Motorola where she focused on mobile I.P. by doing real-time embedded programming for the base radio controller group as part of the iDEN/Nextel project.