Click here to Skip to main content
Click here to Skip to main content

CurrencyConvertor: How to Use gSOAP and Webservices, Part One

, 23 Mar 2007
Rate this:
Please Sign up or sign in to vote.
How to auto-generate VC++ source and include it in your project

Introduction

In this article, I explain how to build a web service client from a WSDL file. I am releasing this project to help those who wish to begin to use a web service with gSOAP. I won't, however, be explaining about XML Serialization, Transient Types, Memory Management, etc.

I split the article into two parts for easier learning and better understanding. In Part One, I will explain how to get the class from the WSDL file to be used in Visual C++ 6. In Part Two, I show you how to use the classes generated with gSOAP.

To begin, you will want:

  • gSoap Toolkit - Download gSoap Toolkit for Windows and unzip it in a directory. You can download it form various sites. I used the site SourceForge and I downloaded the last release: gsoap_win32_2.7.8c.zip
  • WSDL - Download the "WSDL Schema Location" and save it with a WSDL extension. I used this WSDL; you can use another like CryptoService, DotGetLocator, etc.

Info: I used a free web service from WebserviceX.NET. If their server is busy and you get the the error "service unavailable," see if it's working here. After downloading the file, you have to build a C++ class from the WSDL file. Go to the gSoap directory and open the bin sub-folder, something like this: D:\gsoap-win32-2.7\bin. Here, you find two executable files:

  • wsdl2h.exe allows you do bindings in a C/C++ header file (*.h) from the WSDL file you downloaded before. (intermediate header)
  • soapcpp2.exe allows you to build a class with C++ formatting from the intermediate header.

WSDL Importer: Generate the File with C++ Bindings

Copy the WSDL to this directory and run wsdl2h.exe like this:

wsdl2h -o WSCurrencyConv.h CurrencyConvertor.wsdl 
Sample use of wsdl2h

In the shell, you'll see some warning (ignore this) and at the end "To complete the process, compile with: soapcpp2 WSCurrencyConv.h". If all works fine, you'll see a new file in the directory that will be WSCurrencyConv.h (or the name you write at the command line).

N.B. You shouldn't have problems, but if you do, check the name and path you entered and try again.

gSOAP Compiler: Generate the Proxy and XML Serialization Routines in Source-code Format

Run soapcpp2.exe like this:

soapcpp2 -ID:\gsoap-win32-2.7\Import WSCurrencyConv.h
Sample use of soapcpp2

To run this executable, you need to set the path for the gSOAP import, something like this: D:\gsoap-win32-2.7\import. This is similar to what I did before with:

-ID:\gsoap-win32-2.7\Import

The second parameter is the file *.h you entered the first time with wsdl2h. If it works, you'll see in the last line "Compilation successful". Now in the directory, you'll see a few new files.

N.B. You shouldn't have problems, but if you do, check that the path for the import file exists. Otherwise, you can copy all the files in the import directory to the bin directory and try again.

The new files will be:

  • CurrencyConvertorSoap.ConversionRate.req.xml
  • CurrencyConvertorSoap.ConversionRate.res.xml
  • CurrencyConvertorSoap.nsmap
  • soapC.cpp
  • soapClient.cpp
  • soapClientLib.cpp
  • soapCurrencyConvertorSoapObject.h
  • soapCurrencyConvertorSoapProxy.h
  • soapH.h
  • soapServer.cpp
  • soapServerLib.cpp
  • soapStub.h

Using the Visual C++

Now you have all you want to begin deploying your application with Visual C++.

Include Self-generated Code into Visual C++ Projects:

  1. You need to include in your application the files below:
    • soapC.cpp
    • soapH.h
    • soapClient.cpp
    • soapStub.h
    • CurrencyConvertorSoap.nsmap
    • soapCurrencyConvertorSoapProxy.h
    • stdsoap2.h (This file in D:\gsoap-win32-2.7\import is the same for all the SW)
    • stdsoap2.cpp (This file in D:\gsoap-win32-2.7\import is the same for all the SW)
  2. Set the no precompiler header for the CPP files before:
    • Go to Project Settings (Alt-F7)
    • Change the Settings for all configurations
    • Select the CPP file before adding to the project (soapC.cpp, soapClient.cpp, stdsoap2.cpp)
    • Go to the C++ tab, select the category "Precompiled headers" and select the radio button "Not using precompiled headers"
    VC++ settings
  3. Set the Namespace, select the file stdafx.cpp and include the file CurrencyConvertorSoap.nsmap with this line:
    • #include "CurrencyConvertorSoap.nsmap"
  4. Link Ws2_32.lib to the project for use the Windows Sockets 2 API:
    • Go to Project Settings (Alt-F7)
    • Change the Settings for all configurations
    • Go to tab Link, category General, and add Ws2_32.lib to the Objcet/Library modules
    VC++ settings

The Project is ready to communicate with the WS. You have all the classes you need to begin.

N.B You could get this warning (shown below), but don't worry and go ahead. This warning is derived from the self-generated class with gSOAP; gSOAP doesn't check the maximum characters.

Warning

Points of Interest

I read many books online. I find that there are numerous mistakes and that all the examples are unusable. These books may have all you want to know in order to pass a university test, but there is too much information to begin a project. Irritated, I did this project to let you to begin to write a WS client.

History

  • 20 Mar 2007: Second release - Article update
  • 12 Jul 2006: First release

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Share

About the Author

Dr.Luiji
Software Developer (Senior) Imagicle
Italy Italy
Bertoneri Luigi, alias Dr.Luiji
Bachelor of Science in Computer Science, year 2K - University of Pisa (Italy).
 
I'm a developer with more than 10 years of experience. I like the new technology, Windows, iOS and Android.
I love challenges.
 
Skills:
- Language: Android, Objective-C, C++, C#, Java
- Platform: Windows, .NET
- Technology: Too much...
 
I currently work and live in Italy.
Music I listen to: Tool, Slipknot, NIN, Korn, Perfect Circle, Dry Kill Logic, Godsmack, and more.

Comments and Discussions

 
QuestionProblem with Use MFC in a astatic library PinmemberMinoo Khazeni20-Apr-14 20:54 
QuestionIs my appraoch correct for HTTPS? Pinmemberconacher5-Jul-12 4:29 
QuestionQuestion on creating a session. Pinmembersandeep_sinha7-Jun-12 4:37 
AnswerRe: Question on creating a session. PinmemberDr.Luiji7-Jun-12 8:51 
GeneralRe: Question on creating a session. Pinmembersandeep_sinha7-Jun-12 19:20 
GeneralRe: Question on creating a session. PinmemberDr.Luiji8-Jun-12 1:14 
QuestionQuery PinmemberRoshan S. Deshmukh5-Jun-12 21:45 
AnswerRe: Query PinmemberDr.Luiji6-Jun-12 0:57 
GeneralRe: Query PinmemberRoshan S. Deshmukh6-Jun-12 1:54 
GeneralRe: Query PinmemberDr.Luiji6-Jun-12 2:10 
GeneralRe: Query PinmemberRoshan S. Deshmukh6-Jun-12 2:18 
GeneralRe: Query PinmemberDr.Luiji6-Jun-12 9:28 
GeneralRe: Query PinmemberRoshan S. Deshmukh6-Jun-12 19:30 
GeneralRe: Query PinmemberDr.Luiji7-Jun-12 9:53 
GeneralRe: Query PinmemberRoshan S. Deshmukh7-Jun-12 22:49 
GeneralRe: Query PinmemberRoshan S. Deshmukh7-Jun-12 21:13 
GeneralRe: Query PinmemberDr.Luiji8-Jun-12 1:10 
GeneralRe: Query PinmemberRoshan S. Deshmukh8-Jun-12 1:51 
GeneralRe: Query PinmemberDr.Luiji8-Jun-12 9:30 
GeneralRe: Query PinmemberRoshan S. Deshmukh12-Jun-12 0:04 
GeneralRe: Query PinmemberDr.Luiji12-Jun-12 1:55 
GeneralRe: Query PinmemberRoshan S. Deshmukh13-Jun-12 19:19 
GeneralRe: Query PinmemberDr.Luiji14-Jun-12 1:33 
GeneralMy vote of 5 PinmemberSteve Mann28-May-11 19:10 
GeneralRe: My vote of 5 PinmemberDr.Luiji9-Sep-11 22:08 
GeneralMy vote of 4 PinmemberAbsa22-Feb-11 2:59 
GeneralRe: My vote of 4 PinmemberDr.Luiji9-Sep-11 22:07 
GeneralMy vote of 5 PinmemberShilpi Boosar29-Oct-10 21:29 
GeneralRe: My vote of 5 PinmemberDr.Luiji9-Sep-11 22:05 
GeneralRe: My vote of 5 PinmemberSP 2410-Sep-11 6:47 
QuestionI have some questions ?? PinmemberShilpi Boosar27-Oct-10 2:57 
AnswerRe: I have some questions ?? PinmemberDr.Luiji29-Oct-10 0:53 
GeneralRe: I have some questions ?? PinmemberShilpi Boosar29-Oct-10 1:09 
GeneralNot working behind Proxy [modified] PinmemberBinni shah11-Jul-10 19:17 
GeneralRe: Not working behind Proxy PinmemberDr.Luiji19-Jul-10 1:53 
GeneralRe: Not working behind Proxy PinmemberBinni shah19-Jul-10 6:10 
GeneralRe: Not working behind Proxy PinmemberDr.Luiji19-Jul-10 21:07 
Generalmod_gsoap apache error Pinmemberamit_tare17-Apr-10 0:43 
GeneralRe: mod_gsoap apache error PinmemberDr.Luiji9-Apr-10 3:32 
GeneralRe: mod_gsoap apache error PinmemberJipeng Tao9-May-10 21:50 
GeneralI have an error when getting the conversion rate. Pinmemberwaleed8216-Aug-09 2:19 
GeneralRe: I have an error when getting the conversion rate. PinmemberDr.Luiji16-Aug-09 10:27 
GeneralRe: I have an error when getting the conversion rate. Pinmemberwaleed8216-Aug-09 21:14 
AnswerRe: I have an error when getting the conversion rate. PinmemberDr.Luiji17-Aug-09 7:09 
QuestionHttps ceritification question PinmemberJenny_air31-Jul-09 4:28 
AnswerRe: Https ceritification question PinmemberDr.Luiji31-Jul-09 11:24 
GeneralRe: Https ceritification question PinmemberJenny_air31-Jul-09 16:26 
GeneralRe: Https ceritification question PinmemberDr.Luiji1-Aug-09 3:22 
GeneralgSOAP for TCP binding and callback events. PinmemberBicycleTheif6-Jul-09 18:49 
GeneralRe: gSOAP for TCP binding and callback events. PinmemberDr.Luiji6-Jul-09 22:26 

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
Web01 | 2.8.140814.1 | Last Updated 23 Mar 2007
Article Copyright 2007 by Dr.Luiji
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid