Click here to Skip to main content
Click here to Skip to main content
Go to top

IsoapTypeMapper interface – a C++ implementation

, 4 Aug 2001
Rate this:
Please Sign up or sign in to vote.
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.
<!-- Download Links -->

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

Share

About the Author

Avinash Lakshman

United States United States
No Biography provided

Comments and Discussions

 
GeneralUsing UDT for webservice methods Pinmemberaslamshikoh28-Dec-07 9:25 
GeneralThank you PinmemberKen M12-Dec-07 19:25 
GeneralcomplexTypes with XML-Element-Attributes? [modified] PinmemberThomson659628-Jun-06 0:45 
GeneralSOAP help Pinmemberhittmann4@hotmail.com8-Jul-04 21:09 
GeneralMore compile errors PinsussJake Repp27-Aug-02 13:00 
GeneralAbout handling soap:header PinmemberAnonymous23-Sep-01 22:51 
GeneralCompile errors PinmemberAnonymous6-Aug-01 18:41 
GeneralRe: Compile errors Pinmemberlijinniu28-Aug-02 16:45 
GeneralObject-oriented database design and implementation Pinmemberkushibhai6-Aug-01 7:17 
GeneralDead Link To Src PinmemberColin Beales6-Aug-01 4:16 
GeneralRe: Dead Link To Src PinmemberChris Maunder6-Aug-01 4:34 
GeneralRe: Dead Link To Src PinsussAnonymous6-Jul-05 12:25 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

| Advertise | Privacy | Mobile
Web03 | 2.8.140916.1 | Last Updated 5 Aug 2001
Article Copyright 2001 by Avinash Lakshman
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid