Click here to Skip to main content
65,938 articles
CodeProject is changing. Read more.
Articles
(untagged)

IsoapTypeMapper interface � a C++ implementation

0.00/5 (No votes)
4 Aug 2001 1  
This article I provides an implementation of the ISoapTypeMapper interface in C++ for serializing custom objects into XML and sending them over the wire using SOAP.

Introduction

Recently, I have been doing a lot of reading on SOAP and trying to familiarize myself with the MS SOAP Toolkit (version SP2). The samples that come with the toolkit are pretty neat, in that they have quite a bit of C++ samples too. As with any distributed application the fun lies in passing complex types as arguments to methods over the wire as opposed to primitive data types. In this article I have provided an implementation of the ISoapTypeMapper interface in C++ (using ATL)� for serializing custom objects into XML and sending them over the wire using SOAP. This article assumes that the reader is familiar with SOAP, ATL and with the set up of IIS for running the SOAP apps and has the MSSOAP toolkit SP2 installed.

The project

This project, as will be evident, is made up just to illustrate the implementation of the ISoapTypeMapper interface in C++ for complex objects. The aim of this article is to show you how to serialize two COM objects (namely Address and Dealer) into XML and send them over the wire using SOAP. The description of the two objects is shown below :

  • The Address object has 5 properties namely "Name", "Street", "City", "State" and "Zip" all defined as strings.

  • The Dealer object has 2 properties namely "Id" as string and "Address" as the above defined "Address" object.

The VC++� project shows the implementation of these objects and also the implementation of 2 other objects namely AddressMapper and DealerMapper which actually implement the ISoapTypeMapper interface and help in serializing the "Address" and "Dealer" objects respectively into XML.

There are two VB projects one called CPlusPlusAddress.vbp and the other Client.vbp. The CPlusPlusAddress.vbp is an ActiveX DLL project which is the Web Service implementation. It basically consists of 4 methods whose functionality is defined below:

  1. ProcessAddress - accepts an Address object as parameter and return a String which is actually a concatenation of all strings which make up the Address object.
  2. EchoAddress -- accepts an Address object as parameter and returns the same the Address object.
  3. ProcessDealer -- accepts a Dealer object as parameter and return a String which is actually a concatenation of all strings which make up the Dealer object.�������
  4. EchoDealer -- accepts a Dealer object as parameter and returns the same the Dealer object.

The other VB project Client.vbp is a standard EXE and invokes the methods exposed the CPlusPlusAddress Web Service.

Getting Started

First compile the C++ project which actually registers the type mappers and the Address and Dealer COM objects used by the Web Service and the client. Then compile the CPlusPlusAddress.vbp project and ideally you will need to generate the .wsdl and .wsml files. But the project contains the files in the WSDL folder. Make sure create a virtual directory in IIS and name it CPPAddress. This virtual directory must actually point to the WSDL folder which contains the wsdl and wsml files. Then compile the Client.vbp project and you should be able to run the application.

The AddressMapper object

The code for the AddressMapper object is pretty self explanatory. The workings of the relevant individual  methods of the ISoapTypeMapper interface are explained below:

Init() - Since the all properties in Address object are strings we simply retrieve the string mapper that comes with Soap toolkit and store it in the m_pStringMapper element.

read() - the read method just reads the values in the incoming node object and builds an Address object with the values and return it.

write() - the write methods reads the values of the individual properties of the Address object and writes the XML to be sent over the wire.

The DealerMapper object

The workings of the DealerMapper object are similar to that of the AddressMapper object. The DealerMapper object uses the AddressMapper object to serialize/deserialize the Address part of the Dealer object.

Conclusion

The article itself doesn't do much more than describe the projects that make up the code. The code is very self explanatory. I decided to do this since I found a lot of queries regarding serializing complex data types using C++, which went unanswered in the SOAP mailing lists maintained by Develop Mentor. I spent 2-3 days just trying to find an implementation on the Internet. I hope this sample helps the other folks like me who are frustrated (the way I was ) on not being able to find pointers on doing this using VC++/ATL.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here