You learned about SOAP in "Introduction to SOAP." SOAP is a protocol used to create distributed applications. To enable you to create distributed applications by using SOAP, several SOAP toolkits are available from different vendors. These toolkits include Microsoft's SOAP Toolkit, Apache SOAP Toolkit, Paul Kulchenko's SOAP::Lite, and so on.
Microsoft's SOAP toolkit is an easy-to-use toolkit especially for a developer who uses traditional Microsoft technologies and programming languages, such as COM, Visual Basic, and Visual C++. The first version of the toolkit had certain limitations. One of the main 94 problems with Microsoft SOAP Toolkit Version 1.0 was that it did not implement all required sections of the SOAP specification. In addition, the earlier version of the SOAP Toolkit was an MSDN demo and not a product. However, with Version 2.0 of the toolkit, Microsoft fixed the major bugs and also changed the architecture to make it simpler and intuitive. Also, the new version of the toolkit is a Microsoft product instead of just a demo.
The Microsoft SOAP Toolkit 2.0 allows you to create Web services that expose the functionality of existing COM components. It also allows you to create Web service clients using tools like Visual Basic 6.0. The Microsoft SOAP Toolkit 2.0 includes the following:
Microsoft SOAP Toolkit Version 2.0 provides high-level and low-level interaction APIs. To access the high-level interface, you can use a SOAP toolkit object called SoapClient. This object contains several methods and properties, some of which are included in the following list:
To understand the methods and properties associated with the SoapClient object, consider the following example. You can use the code to connect to a Web service, which adds two numbers, from a Visual Basic client.
As you see in the preceding code, you can call a Web service method as if it were a member of the SoapClient object. This simplifies the development of the client applications.
The SOAP toolkit retrieves information about how to interpret and use a Web service from the WSDL document of the Web service. In addition, the toolkit provides a tool, called the WSDL generator, to SOAP-enable existing COM components. The WSDL generator accepts the path for a COM component as input, analyzes its type library, and creates a Web service consisting of a WSDL file, a WSML file, and an ASP file.
You learned about WSDL files in "Introduction to WSDL." The WSML file is not a standard file. It is a Web Services Meta Language file that is specific to the Microsoft toolkit. WSML is an XML file that maps SOAP messages to the original COM interfaces.
When a COM component method is called and the method returns a value, the value is serialized into SOAP format and passed on to the SoapClient object, which further deserializes the SOAP response and returns the appropriate COM data type. This serialization and deserialization happens automatically when the value passed is compatible to one of the XSD types. When the value is a custom data type or an object, such as an ADODB recordset, then the SOAP toolkit allows the creation of custom type mappers. You will learn to create a custom type mapper in the section "Handling Recordsets and Other Custom Data Types in SOAP Messages."
The SOAP toolkit allows you to create both ASP-based and ISAPI-based Web services. Having discussed the SOAP toolkit in general, we will now move on to creating the Web service from an existing COM component by using the Microsoft SOAP toolkit.
Creating a Web Service by Using the Soap Toolkit 2.0
In this section, you will learn to create a Web service from a COM component.
Before creating the application, it is important to discuss the working of the Web service. The existing COM component contains methods that allow applications to query a database and returns data as an ADODB recordset. The Web service needs to convert this data into SOAP format because the ADODB recordset is not an XSDdefined data type. The requesting application then processes the SOAP message to retrieve and display the data.
The first step in the creation of a Web service is to reuse the existing COM component. The COM component is called GetData.dll. The DLL file for the COM component has several classes. You can use these classes to query the CNS database. This chapter will concentrate on the ExecSP class. The ExecSP class has two methods: getAll() and getByCategory(). The signature of these methods is as follows:
To get the implementation details of these methods
As you see, the ExecSP.getAll() method does not accept a parameter, but it returns an ADODB Recordset object that contains information on the products in the CNS database. The second method accepts the name of a category as a parameter and returns data of all products in this category.
We will now create the Web service that reuses the preceding component. To create a Web service that reuses any COM component, you need to use the Microsoft SOAP Toolkit 2.0.
To create a Web service by using the Microsoft SOAP Toolkit 2.0, follow these steps:
Soap Toolkit 2.0 WSDL Generator Wizard
Naming the Web Service
Figure shows a tree view of the classes and methods that are contained in the COM component
The Component Classes and Methods
When you select the getByCategory() and getAll() methods, a note displays on the screen. The note states that if any method that you select returns a value of a data type that the Soap Toolkit does not recognize, the data type will be written as ??????? in the WSDL file that is generated.
The Soap Listener Information screen is displayed.
In the first text box of the Soap Listener Information screen, type the URL where you want to host the Web service. In this case, you can host the Web service at the http://ServerName/ProductSummary URL.
The SOAP Listener Information Screen
Specifying the Folder for the WSDL and WSML Files
As you can see, UTF-8 is selected by default. You also need to specify the folder where the files that the wizard generates will be saved.
Clicking on the Next button starts the file generation process. After the files are generated, you will get a warning message, as shown in Figure. The message indicates that some of the methods had data types that the Soap toolkit didn't understand; therefore, the data types are replaced by ?????? in the WSDL file.
The Data Type Error Message
The ProductSummary.wsdl File
The ProductSummary.wsdl file is the Web service description file that contains information about the Web service and the operations that it supports. The operations supported by a Web service are contained in the <message> elemen of the WSDL file. We will now discuss the content of the WSDL file in detail.
The WSDL file contains the declarations for the SOAP messages that interact with the getAll() method of the component. The syntax of the SOAP messages as generated by the wizard is as follows:
As discussed earlier, the getByCategory() method accepts a string as a parameter and returns a recordset. Therefore, to interact with the getByCategory () method, you need to declare a pair of SOAP messages as shown here:
As you can see, the preceding code snippet contains the type='xsd: ???????'/> declarations. This is because the return type of the methods in the COM component is ADODB. Recordset, which is not a data type that the SOAP toolkit recognizes.
After declaring the pair of SOAP messages, you need to bind the operations (getAll and getByCategory) to the corresponding messages. You can accomplish this by using <portType> declarations. For example, the operation getAll has an input message, getAll, and an output message, getAllResponse. The following code snippet shows the <portType> declarations:
After binding the operations to corresponding messages, you need to bind the operations to corresponding ports. To do this, you use the <bindings> section as shown in the following code snippet:
Next, the WSDL file contains the <service> section that identifies the name of the Web service and its location. The <service> section is shown in the following code:
The ProductSummary.wsml File
Next, consider the WSML file that the wizard creates. This file is used to map the Web service and its operation to the COM component and its methods. The WSML file is an XML document as shown:
The ProductSummary.asp File
The ASP file provides an interface for external applications to communicate with the Web service. The content of the ASP file is as shown:
The wizard has created a basic Web service for you. However, you will not be able to use this Web service because the WSDL file still has the ?????? declarations for the values returned by two of the SOAP messages. You will fix this in the next section.
Handling Recordsets and Other Custom Data Types in SOAP Messages
To handle custom data types that the SOAP toolkit does not support, you need to modify the declarations in the WSDL file. Follow these steps to modify the declarations:
Open the WSDL file in a text editor. Consider the <types> node in the WSDL file.
The ComplexType declaration in the preceding code depends on the data type for which you need to create a custom mapper. For example, consider a method that returns an object of the type Distributor. The following code is the declaration for the Distributor class:
You can create a <complexType> declaration for the Distributor class as follows:
After declaring the complex type for the recordset, you need to replace the ??????? in the data type declarations of the WSDL file with the complex type that you created:
Now, the WSDL file is created. The next step is to create a component that will do the custom type mapping. To do so, perform the following steps:
The project contains a default class Class1. This class handles the type mapping; therefore, this class should implement the SoapTypeMapper interface. To do this, you need to add the following code to the class:Implements MSSOAPLib.ISoapTypeMapper
In addition to the SoapTypeMapper interface, the class should implement the methods of the interface. Therefore, you need to add the following code to the class:
The preceding code contains the ISoapTypeMApper_Write() function, which is used to perform the actual type mapping. Therefore, the contents of the recordset are converted into a data stream object, and the string containing the XML data is passed to the SoapSerialized object.
After writing the code, you need to compile it into a DLL file. This creates a custom type mapper DLL that you need to bind to the Web service. To bind the mapper DLL to the Web service, perform the following steps:
The file currently contains a reference to the GetData.dll COM component, as shown here:
The Web service for CNS is now created. After creating the Web service, you need to test it before deploying it at the client site.
Testing the Web Service
To access the Web service, you need to create a proxy component that consumes the Web service. The clients, in turn, will use this component to access the Web service. To create a proxy component, perform the following steps:
As you can see, both getAll() and getByCategory() function in a similar way. Both initialize the SoapClient object by calling the mssoapinit() method. Then the code calls the Web service method, getAll(), which returns the XML data that is converted to a string value.
Compile the project and create the DLL file.
Next, you will create a client application in Visual Basic 6.0. his application connects to the Web service, calls one of its methods, and displays the data that the service returns. The client application can connect to the Web service through the client proxy that you have created. As discussed earlier, the proxy component returns a string value, which contains the XML form of the recordset object, returned by the original COM component. Therefore, the client application needs to convert this data back to a recordset object and display it in a DataGrid (OLEDB) control. To convert the XML data to a recordset object, perform the following steps:
We will refer to the application that we created in the previous steps as the test application.
The Test Application
The preceding code retrieves a string containing the XML data. Next, the code writes the string into an ADODB.Stream object and then inserts the string into a recordset object. As you will notice, the whole process is the reverse of what you did to serialize the data in recordset in the custom type mapper application. Finally, the code sets the data source property of the DataGrid control to Adodc1, where Adodc1 is the instance of the ADODC control on the form.
Setting Up the Web Service
Web service files and the test client application are ready. Now, you need to set up the Web service. To do this, perform the following steps:
Internet Services Manager
In the Virtual Directory Creation Wizard, you need to specify the name or alias for the virtual directory.
The Virtual Directory Creation Wizard
In the resultant screen, you need to specify the path for the Web site content directory. The resultant screen is shown in Figure.
The Web Site Content Directory Screen
The Access Permissions Screen
After setting up the Web service, you can now run the test application and verify the data that is displayed in the DataGrid control.
Securing the Web Service
After creating and testing the Web service, the next step is to secure the Web service. SOAP currently does not implement security; instead, it delegates security to the Transport layer. In this case, the Transport layer is HTTP. A Web service that you have created is an example of a Web application running on the IIS/Windows 2000 platform. Therefore, all methods of securing Web applications also apply to the Web service.
Securing a Web service includes preventing unauthorized access to it. You can accomplish this by authenticating the users who connect to the Web service. Several methods allow you to authenticate users. However, if you do not use an authentication method, the Anonymous Access mode is enabled by default.
We will now discuss the authentication methods in the following list:
Base-64 encoding/decoding is a convention for converting binary data to a string of printable, alphanumeric characters. This technique is taken from RFC 1521.
Having looked at various ways in which you can secure your Web service, you will now secure your Web service by using the basic authentication method. To do this, perform the following steps:
The Directory Security Dialog Box
Now,try to connect to the Web service from the test client application that you created. You will get an Access Denied error message.
For the client to authenticate itself to the Web service, make the following changes to the ClientProxy DLL:
You can use the ConnectorProperty() method of the SoapClient class to pass the username and password to the Web service. If the virtual directory where the Web service is located requires authentication, you can pass it as shown:
Compile and generate the ClientProxy.dll file again with the previous changes. Run the test application and verify the connectivity to the Web service.
The basic authentication is now enabled for the Web service. The next step is to make the authentication more secure by adding an SSL Certificate. To do this, you can use the SSL trial feature at VeriSign.com.
However, before you request for a trial certificate, you need to prepare a certificate request. To prepare a certificate request, perform the following steps:
The Web Site Properties Dialog Box
The IIS Certificate Wizard
Creating the Certificate Request
The Name and Security Settings Screen
In the screen shown in Figure, decide the encryption strengths for the keys that the certificate generates. The bit length of the encryption key depends on your need for security and speed. A higher bit length makes your application more secure, but if you are running a processor- and memory-intensive application over SSL, then a larger key might slow down your application.
Saving the File with the CSR.
The content is encrypted, so it is not intelligible.
The next step is to approach a CA for an SSL certificate.The certificate will be in a format similar to the request. A sample certificate response sent through e-mail is as shown:
To install the certificate, perform the following steps:
The Pending Certificate Request Page.
You now have a server certificate installed. To securely connect to the Web service, you now have to use https instead of http.
To connect to the newly secured Web service from the Visual Basic client, perform the following steps:
You have created a secure and functional Web service. You can now test the functioning of the service from an ASP page. The ASP page also uses the client proxy that you have created. The code for the ASP page is given next:
The code for the ASP page is similar to the test Visual Basic application you created previously. Here, a string that contains the XML data is received from the Web service and an ADODB recordset is populated from the data. The first three fields of the first record in the recordset are then displayed. Create a virtual directory for this ASP page and verify the functioning of the Web service.
XML Related Interview Questions
|Soap Tool Interview Questions||HTML Interview Questions|
|PHP Interview Questions||ASP.NET Interview Questions|
|PHP5 Interview Questions||Java Interview Questions|
|CSS Interview Questions||XSLT Interview Questions|
|Java XML Interview Questions||XMLHttpRequest (XHR) Interview Questions|
|ebXML Interview Questions||XML DOM Interview Questions|
|XML-RPC Interview Questions||XSD Interview Questions|
|Soap Web Services Interview Questions||XSL Interview Questions|
|Xml Publisher Interview Questions|
Basics Of Xml
Basics Of Web Services
Introduction To Soap
Introduction To Uddi
Introduction To Wsdl
Creating A Web Service Using The Microsoft Soap Toolkit
Building Web Applications On The .net Platform
Creating An Asp.net Web Service
Creating A Web Service From An Interface
Introduction To The Atl Server
Creating A Web Service Using The Atl Server Library
Design And Creation Of The Knowledge Share Web Service
Introduction To Java Xml Technologies
Developing Java Web Services
Design And Creation Of A Web Service Using The Ibm Toolkit
Introduction To Mobile Applications
Creating A Mobile Application That Consumes A Web Service
Web Services Development With Jdeveloper
Creating Web Services Using Perl
Integration Of Xml Web Services With The Office Xp And Sql
Server 2000 Toolkits
All rights reserved © 2018 Wisdom IT Services India Pvt. Ltd
Wisdomjobs.com is one of the best job search sites in India.