使用gSOAP与WebService - 第一部分 为VC++从WSDL读取信息

CurrencyConvertor - How use gSOAP and WebServices - Part 1 Get ready with VC++ 6 from WSDL file

Screenshot - CurrencyConvertor-Part11.jpg

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 won't 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 VC++ 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.)

After downloading the file, you have to build a C++ class (from the wsdl file). Go to gSoap dir and open 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 : Generates the file with C++ bindings

Copy the wdsl 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 param 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 VC++

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

Include self-generated code into VC++ project:

  1. You need to include in your app the files below:
    • soapC.cpp
    • soapH.h
    • soapClient.cpp
    • soapStub.h
    • CurrencyConvertorSoap.nsmap
    • soapCurrencyConvertorSoapProxy.h
    • stdsoap2.h (This file is in the D:/gsoap-win32-2.7/import is the same for all the SW)
    • stdsoap2.cpp (This file is in the 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.
    • 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 the 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, add Ws2_32.lib to 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 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

  • 12/07/2006: First release
<script src="/script/togglePre.js" type="text/javascript"></script>

About Dr.Luiji


Bertoneri Luigi, alias Dr.Luiji
Bachelor of Science in Computer science, year 2000 - University of Pisa (Italy).
I currently live in Italy.
Music I listen to: Slipknot, Type O Negative, Tool, Mushroomhead, Dry Kill Logic, System of a Down, White Zombie, RA, Slayer.

Click here to view Dr.Luiji's online profile.

 
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值