As you begin to move more of your code over onto the Internet via Web Services you will notice that creating the actual server is the simplest part. Take the Microsoft WSDL (Web Service Description Language) SOAP Toolkit Wizard and apply it to your COM, and it creates the necessary files on the server for you. Don't you wish you could simply run another wizard and have it create the files for a client just as easily? That's what I have done here. I've created a wizard that creates the client files for you, based on the Simple Object Access Protocol (SOAP) Toolkit V2, SP 2.
Normally, you are most likely taking the samples from the Microsoft SOAP Toolkit and simply changing them to suit your needs for the new service you have recently put online. I hope to show you a quick and easier way of doing this. I have developed a wizard that will basically convert your WSDL file into a set of workable files for the client. These include the Visual Basic and ASP source.
First, download the WSDL Converter that I have created. Unzip the package, and load up the Visual Basic project "WSDLConverter.vbp." The text box labeled "WSDL" is where you will state the location of your WSDL file. The "Save To" text box should already be populated with your current user's personal directory (this is done in the Form Load event).
Part I Testing the Wizard
Step 1: Convert the WSDL
Let's first see what this project does. Hit F5, or "Run, Start." The applications main window will appear. I have defaulted the "WSDL" file location to my existing credit card validation service, which I showed you how to create in a previous article. (see http://www.15seconds.com/issue/010725.htm). Hit the "Convert" button, and allow the program to run it course. Hit the "Exit" button and minimize the instance of Visual Basic (VB).
Now, in the folder, which is named in the "Save To" text box, you should see three files.ccauth.vbp, ccauth.cls, and ccauth.asp. Let's start by opening up the ccauth.vbp file. On my machine, I used all default install locations for the SOAP toolkit, and if you did, you should encounter no errors. Just to double check, take a look at the Project References (Project Menu, References ...) to ensure that we have made available the Microsoft SOAP Type Library. Ensure that this is clicked and hit OK.
Step 2: Making the COM Client
Expand the Class modules, and double click the "ccauth" class. You will notice that this is a very simple method, which creates and calls the necessary SOAP methods, and returns the results. Normally we all would have to code this by hand.
Build the ActiveX DLL now, and register it on our machine (File, Make ccauth.dll, choose your location, and hit OK). Once this has been completed, exit VB. You must now register the DLL on your server. This can be done in a variety of ways. Personally I will simply use regsvr32 DLLPath/DllName, like:
Go to Start, Run, and type in:
Regsvr32 c:\15seconds\ccauth.dll
Make sure the path corresponds to where you placed the DLL on your machine.
Step 3: Setting Up the ASP Client
Now we'll move on to the ASP document that was created for us. First, move this document to a live folder off of the root of your Web server. Personally, I placed mine at: "C:\Inetpub\wwwroot\webservices\public\test\ccauth.asp".
Open this document in your favorite text editor. You will automatically notice two things. Once, the code has already been written that creates an instance of the object, as follows:
set ccauthClient = server.createobject("ccauthClient.ccauth")
and there is a local method you can use to call the specific function:
Function checkcc( ByVal ccnumber, ByVal cctype)
On Error Resume Next
checkcc=ccauthClient.checkcc(ccnumber, cctype)
end function
All you need to do now is call your method like:
Response.write checkcc( "4111111111111111", "V")
And save.
Step 4: Testing the Client
You can now load the page up in your browser. (My URL is http://localhost/webservices/public/test/ccauth.asp.) If you get an error due to security permissions, make sure you allow IUSER_machinename access to this file.
What you should see on the page now is: "Card is OK!" You have now consumed a Web Service in four simple steps.
Part II A Closer Look at the Wizard
This section is intended for those that wish to learn more about how exactly I created this wizard, or for those that have problems. If you would like to add more functionality, please do, and email me your updates. I only plan on covering the essential portions of the processing, and only giving an overview of some of the non-essential portions.
First we'll take a look behind the "Convert" button. I thought it was necessary to ensure that what the end user put in as a file location (URL) for the WSDL was a valid URL and the URL contained valid XML. My reasoning behind this was to avoid any extra processing if the URL supplied was an incorrect one.
Once we have validated the URL and the actual contents of the URL as being XML, we call the method "convertWSDL." If you're wondering why some of that method's code looks somewhat familiar, it is because I borrow a lot of it from Microsoft's Developer Network (see http://msdn.microsoft.com/library/en-us/soap/htm/wsdlom_ref_wsdlreader_1ctu.asp).
What does this code do? We must first understand the basic structure of a WSDL document. Here is an overview of the structure.
Basically, at the topmost level, we have the Service, an example of the Service would be our "ccauth" service. Each Service can have many "Ports" bound to many Operations. Think of Ports as ways in which we can access the service -- for example, "RPC" over "HTTP," which means Remote Procedure Call over Hypertext Transport Protocol (what we are doing here). For these many Operations, or what I like call "methods," you have many Mappers (or parameters).
This code basically loops and creates the source for a Visual Basic COM project at the Service level. It also loops at each sublevel, gathering the necessary bits of information to complete the necessary code for the COM and the ASP document. In the end, it produces three simple documents, which saved you from spending precious time to create them by hand.
One big thing you will notice is that I needed to add in an additional method call within this nested looping structure:
This is because of the known bug in the Microsoft SOAP Toolkit V2, SP2. This method simply makes another request for the WSDL document and parses out the namespace for the given operation, which is necessary for the Operation (Method) call.
You can review the various other methods that I created in order to simply the output of the files. I feel I have documented each sufficiently. These are "outputVBP," "outputCLS," "outputASPHeader," "AddASPMethod," "closeASPDoc," and "addMethod." The most important of these methods is "addMethod," which builds up the SOAP calling structure within the COM and adds the parameters and all of the necessary endpoints to call the method.
Part III Conclusion
There are a couple of different aspects of this project that most can learn from, as follows:
Using the WSDLReader object to programmatically investigate and work with the entire WSDL document.
Also, the creating of a client for a Web Service, which is always necessary for any Web Service.
And finally putting a couple of ideas together in an unusual fashion in order to save you a lot of time and hassle.
In the end, I hope you will use this wizard to save yourself a bit of time.
I have randomly tested this wizard against a couple of different WSDL endpoints, most of which were successful. For some reason, because the Microsoft SOAP Toolkit doesn't support them or the endpoint WSDL was not correctly formatted to the WSDL specification, I could not get a few of them to load properly. If you encounter this, please attempt to determine the exact problem, and report it to the appropriate group.
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 and 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.
Stonebroom.ASP2XML(c) is an interface component designed to make building
applications that transport data in XML format much easier. It can be used
to automatically pass updates back to the original data source.
Right now the latest buzzword around town is AJAX. AJAX is an acronym for Asynchronous JavaScript and XML and is a method used to implement remote calling. The problem is that AJAX is only implemented in ASP.NET 2.0. This article will show you one way to implement remote calling without using AJAX or the XMLHttpRequest object. The technique outlined can even be used from classic ASP and is sufficient for most remote calling needs. [Read This Article][Top]
This article is the third and final installment of Alex Homer's series covering the new XML support in Microsoft SQL Server 2005. In it he covers updating the contents of xml columns, comparing traditional XML update techniques with XQuery, and using XQuery in a managed code stored procedure. [Read This Article][Top]
In the second part of his series on SQL Server 2005's new XML support, Alex Homer looks at extracting data from XML columns, comparing traditional XML data access approaches with XQuery, and combining XQuery and XSL-T.
[Read This Article][Top]
Microsoft SQL Server 2005 now offers great support for and close integration with XML as a data persistence format. In the first article of his series examining this new support, Alex Homer offers an overview of how SQL Server 2005 stores XML documents and schemas, examines how it supports querying and manipulating XML documents, and provides a simple test application that allows you to experiment with XQuery. [Read This Article][Top]
In the final article of his series on reading and writing XML in .NET 2.0, Alex Homer looks at how the updated XML document store objects XmlDocument, XmlDataDocument and PathDocument can be used to read, persist and write XML documents and fragments more easily and more efficiently than in .NET 1.x. [Read This Article][Top]
In the final article of his series on reading and writing XML in .NET 2.0, Alex Homer looks at how the updated XML document store objects XmlDocument, XmlDataDocument and PathDocument can be used to read, persist and write XML documents and fragments more easily and more efficiently than in .NET 1.x. [Read This Article][Top]
Alex Homer continues his series on reading and writing XML in .NET 2.0. In part one, we focused on the reading side of things, examining the XmlReader and XmlReaderSettings classes. In this article, we move on to look at the XmlWriter and XmlWriterSettings classes, and how they can be used to write XML documents and fragments more easily and more efficiently than in version 1.x of .NET.
[Read This Article][Top]
Alex Homer continues his series on reading and writing XML in .NET 2.0. In part one, we focused on the reading side of things, examining the XmlReader and XmlReaderSettings classes. In this article, we move on to look at the XmlWriter and XmlWriterSettings classes, and how they can be used to write XML documents and fragments more easily and more efficiently than in version 1.x of .NET. [Read This Article][Top]
In the first part of his series on reading and writing XML in .NET 2.0, Alex Homer discusses the XmlReader and XmlReaderSettings classes. The XmlReader exposes several useful new features and the all new XmlReaderSettings class makes it easy to generate single or multiple instances of an XmlReader with a range of useful properties. [Read This Article][Top]
In the first part of his series on reading and writing XML in .NET 2.0, Alex Homer discusses the XmlReader and XmlReaderSettings classes. The XmlReader exposes several useful new features and the all new XmlReaderSettings class makes it easy to generate single or multiple instances of an XmlReader with a range of useful properties. [Read This Article][Top]
Mailing List
Want to receive email when the next article is published? Just Click Here to sign up.