|
Introduction
This is the second part of a two-part series geared to get you quickly started with Web services and the Microsoft SOAP Toolkit. It will allow you to consume the server that we created in the first part (see http://www.15seconds.com/issue/010725.htm) of this article. Part I shows you how to use the toolkit on the server, and deploy your Web service.
Section 2: The Client -- Consuming the Service
Step 1 -- Sample Client Source Cleanup
As with the server, we will begin our work by looking at the samples in the MicrosoftSimple Object Access Protocol (SOAP) Toolkit. Since we used the "Calc" sample for the server section in Part I, let's copy the same client to our working directory and jump right into the code (C:\Program Files\MSSOAP\Samples\Calc\Client\SrSz\Vb\). Again, let's clean up the source files. We need to rename and delete unwanted source files.
CalcCliSrSzVb.exe delete
CalcCliSrSzVb.vbp rename to CCClient.vbp
CalcCliSrSzVb.vbw delete
Default.htm delete
Step 2 -- Getting the Client Form Ready for Use
This time you should have no problems loading up the Visual Basic project. Once it is fully loaded, rename the project and change the caption on the form to "CCClient" and redesign the form around to look like the following:

Figure 1.1 - A screenshot of the layout for the CCClient form.
Notice that we added a drop-down combo box. This will store our values for the credit card type. Let's add them into the form load event. We also left the Add button on the form, but changed its name to "cmdCheck." You can download this project at anytime at http://15seconds.com/files/010808.zip.
Private Sub Form_Load()
cboCCType.Clear
cboCCType.AddItem "V"
cboCCType.AddItem "M"
cboCCType.AddItem "A"
cboCCType.AddItem "C"
cboCCType.AddItem "D"
cboCCType.AddItem "E"
cboCCType.AddItem "J"
cboCCType.ListIndex = 0
End Sub
Step 3 -- Getting the Client Ready to Access the Server
There are a couple of other things in the client program that need to be changed in order to successfully connect to our server. First, ensure that the base SOAP action URI is correct. This URI is pretty simple to create. With the Microsoft toolkit, it always uses http://tempuri.org/action/CLASS_NAME where CLASS_NAME is the name of the class that you exposed in the object from Part I of this article. In this case it is AUTH.
BASE_SOAP_ACTION_URI is correct. Change this to:
Private Const BASE_SOAP_ACTION_URI = "http://tempuri.org/action/auth."

Figure 1.2 - A screenshot of the Microsoft SOAP Toolkit.
We will also need to add the location of the end point URL -- the ASP document -- which the toolkit created for you. It will be located in the directory where you chose to save the toolkit-generated files.
Private Const END_POINT_URL = "http://localhost/webservices/public/ccauth/ccauth.ASP"
Remove all of these methods:
Private Sub cmdSubtract_Click() deletePrivate Sub cmdMultiply_Click() delete
Private Sub cmdDivide_Click() deletePrivate Sub cmdAdd_Click() delete
We add in the method call for the cmdCheck_Click event:
Private Sub cmdCheck_Click()
txtEquals = "Authorizing..."
DoEvents
Execute "CheckCC"
End Sub
This calls the method "Execute," and we will need to change the section where it loads the parameters:
Serializer.startElement "A"
Serializer.writeString txtA.Text
Serializer.endElement
Serializer.startElement "B"
Serializer.writeString txtB.Text
Let's change it so it reads as follows:
Serializer.startElement "ccnumber"
Serializer.writeString txtA.Text
Serializer.endElement
Serializer.startElement "cctype"
Serializer.writeString cboCCType.Text
And finally, we have to change the reference to the end point URL in this method:
Connector.Property("EndPointURL") = cbEndPoint.Text
To
Connector.Property("EndPointURL") = END_POINT_URL
We now have a full client that should be working.
Step 4 -- Testing Our Client
Remember that if your copy of the client doesn't work, you can just download our version, and test with it instead. Hit F5 to start the Visual Basic (VB) application. Put your test value for a credit card number in the A: text box, and then choose the type and hit "Check."
My test values are:
First Test:
A: 4510000000000000
B: V
Result: Wrong checksum.
Second Test:
A: 4519019173778305
B: V
Result: Card is OK!
According to our algorithm, which is defined in our server, the second credit card number is valid. It meets the requirements that the algorithm has imposed upon it. This does not have anything to do with actual transaction information. This number might not even be a credit card. For example, if I enter the details for my Interac Bank Card, which is not a credit card, it accepts it as being a credit card because it passes the algorithm.
Conclusion: The Client -- Consuming the Service
This article has shown you a very quick an easy way to setup a simple Web Services client to consume the Web Service which we created in the previous article. I hope this two-part article helps you in getting your Web Service online, and fast.
More Information
There are among the many resources on the Internet for Web services that you could bookmarks.
The SOAP specification:
Simple Object Access Protocol (SOAP) 1.1 - W3C Note 08 May 2000
http://www.w3.org/TR/SOAP/
Microsoft SOAP:
SOAP Toolkit 2.0 SP2 - Download
http://msdn.microsoft.com/downloads/default.asp?URL=/code/sample.asp?url=/MSDN-FILES/027/001/580/msdncompositedoc.xml
IBM SOAP:
Web Services Toolkit
http://www.alphaworks.ibm.com/tech/webservicestoolkit
Develop.com (Don Box):
Don Box - The Drive to 2005 and Beyond
http://www.develop.com/dbox/
Developer Links:
Excellent resource for more SOAP-related links
http://www.aspfree.com/devlinks/search.asp?catid=72
Santra.com:
A Web service monitoring and alerting company providing services to help you with your deployment and ongoing maintenance.
http://www.santra.com
About the Author
Robert Chartier has worked in the information technologies field for more than 7 years. While studying at college he began his career working as a software and hardware technician at the college, supporting a user base of thousands of students and hundreds of instructors. Once his college days were finished he moved on to full-time studies at a university in the lower mainland of British Columbia, and landed a full-time job developing large projects for distribution on many platforms, mediums, and languages.
Next, he moved onto Stockgroup, where he was able to tap into the Internet development market on a larger and more focused scale. In his spare time he began writing and producing content for developer-specific sites focusing on Microsoft technologies (ASP, COM/COM+, etc.). He has also been a part of many open forums on cutting-edge technologies such as the .NET Framework, Web services (SOAP), and has been invited to speak at large developer conferences and contribute to many technical publications.
His next step was to take a position with a large B2B training marketplace, Thinq.com. At Thinq he developed many tools, including a very comprehensive search engine with custom business rules for weighting, sorting, and analysis (COM+). This led him into strong development with beta versions of Commerce Server 2000 and BizTalk Server 2000.
His next opportunity included a large Internet development effort using technologies such as JSP (Java Beans, J2EE), Oracle, WebLogic, etc.
Robert Chartier can be reached at rob@aspfree.com.
|