锐英源软件
第一信赖

精通

英语

开源

擅长

开发

培训

胸怀四海 

第一信赖

当前位置:锐英源 / 英语翻译 / CurrencyConvertor:如何使用gSOAP和Webservices
服务方向
人工智能数据处理
人工智能培训
kaldi数据准备
小语种语音识别
语音识别标注
语音识别系统
语音识别转文字
kaldi开发技术服务
软件开发
运动控制卡上位机
机械加工软件
软件开发培训
Java 安卓移动开发
VC++
C#软件
汇编和破解
驱动开发
联系方式
固话:0371-63888850
手机:138-0381-0136
Q Q:396806883
微信:ryysoft

锐英源精品开源心得,转载请注明:“锐英源www.wisestudy.cn,孙老师作品,电话13803810136。”需要全文内容也请联系孙老师。


CurrencyConvertor:如何使用gSOAP和Webservices


前言


我以前写过文章,描述过直接写个.h文件来写gSOAP服务器,本文介绍了从wsdl文件来生成服务代码,虽然内容有些旧,但在过程上有参考意义。说它旧,因为还是用的VC6,如果在校学生看本文还合适,现在工作里普遍用了VS2010、VS2013、VS2015等等。


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. 在本文中,我将解释如何从WSDL文件构建Web服务客户端。我正在发布这个项目,以帮助那些希望开始使用gSOAP开发Web服务的朋友。但是,我不会解释XML序列化,瞬态类型,内存管理等。
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. 我将文章分为两部分,以便于学习和更好地理解。在第一部分中,我将解释如何从WSDL文件中获取要在Visual C ++ 6中使用的类。在第二部分中,我将向您展示如何使用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 gSoap Toolkit - 下载适用于Windows的 gSoap Toolkit并将其解压缩到一个目录中。您可以从各种站点下载它。我使用了 SourceForge站点并下载了最新版本: 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. WSDL - 下载“WSDL Schema Location”并使用WSDL扩展名保存它。我用过这个WSDL; 你可以使用另一个像CryptoService,DotGetLocator等。

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: 信息:我使用了WebserviceX.NET提供的免费Web服务。如果他们的服务器很忙并且您收到错误“服务不可用”,请查看它是否在此处工作。下载文件后,您必须从WSDL文件构建C ++类。转到gSoap目录并打开bin子文件夹,如下所示:D:\  gsoap -win32-2.7 \ bin。在这里,您找到两个可执行文件:

  • wsdl2h.exe allows you do bindings in a C/C++ header file (*.h) from the WSDL file you downloaded before. (intermediate header)wsdl2h.exe允许您从之前下载的WSDL文件中对C / C ++头文件(* .h)进行绑定。(中间状态头文件)
  • soapcpp2.exe allows you to build a class with C++ formatting from the intermediate header.soapcpp2.exe允许您从中间状态头文件构建具有C ++格式的类。

WSDL Importer: Generate the File with C++ Bindings WSDL导入程序:使用C ++绑定生成文件

Copy the WSDL to this directory and run wsdl2h.exe like this: 将WSDL复制到此目录并运行wsdl2h.exe,如下所示:

                    wsdl2h -o WSCurrencyConv.h CurrencyConvertor.wsdl 

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). 在shell中,您将看到一些警告(忽略这一点),最后“要完成该过程,请使用:soapcpp2 WSCurrencyConv.h进行编译”。如果一切正常,您将在目录中看到一个新文件,该文件将是WSCurrencyConv.h(或您在命令行中写入的名称)。
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 gSOAP编译器:以源代码格式生成代理和XML序列化例程

Run soapcpp2.exe like this: 像这样运行soapcpp2.exe

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

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: 要运行此可执行文件,您需要设置gSOAP导入的路径,如下所示:D:\gsoap -win32-2.7 \ import。这与我之前的做法类似:

                    -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. 第二个参数是您用wsdl2h时第一次输入的文件* .h。如果它有效,你会在最后一行“编译成功”中看到。现在在目录中,您将看到一些新文件。
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. 注意:您不应该遇到问题,但如果这样做,请检查导入文件的路径是否存在。否则,您可以将导入目录中的所有文件复制到bin目录,然后重试。
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++在VC中使用


Now you have all you want to begin deploying your application with Visual C++.现在,您已经准备好使用Visual C ++开始部署应用程序了。

Include Self-generated Code into Visual C++ Projects: 将自生成的代码包含在Visual C ++项目中:

  • You need to include in your application the files below: 您需要在您的应用程序中包含以下文件:
  • soapC.cpp
    • soapC.cpp
    • soapH.h
    • soapClient.cpp
    • soapStub.h
    • CurrencyConvertorSoap.nsmap
    • soapCurrencyConvertorSoapProxy.h
    • stdsoap2.h ()
    • stdsoap2.cpp ()
  1. Set the no precompiler header for the CPP files before:对上面的CPP文件设置不使用预编译头
    • Go to Project Settings (Alt-F7) 转到项目设置(Alt-F7)
    • Change the Settings for all configurations更改所有配置的“设置”
    • Select the CPP file before adding to the project (soapC.cpp, soapClient.cpp, stdsoap2.cpp) 在添加到项目之前选择CPP文件(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"转到C ++选项卡,选择“预编译头”类别,然后选择单选按钮“不使用预编译头”

header

  1. Set the Namespace, select the file stdafx.cpp and include the file CurrencyConvertorSoap.nsmap with this line: 设置命名空间,选择文件stdafx.cpp并在此行中包含文件CurrencyConvertorSoap.nsmap
    • #include "CurrencyConvertorSoap.nsmap"
  2. Link Ws2_32.lib to the project for use the Windows Sockets 2 API: 将Ws2_32.lib链接到项目以使用Windows套接字2 API:
    • Go to Project Settings (Alt-F7) 转到项目设置(Alt-F7)
    • Change the Settings for all configurations更改所有配置的“设置”
    • Go to tab Link, category General, and add Ws2_32.lib to the Objcet/Library modules转到选项卡链接,类别常规,并将Ws2_32.lib添加到Objcet / Library模块

lib

 

版权所有 Copyright(c)2004-2021 锐英源软件
公司注册号:410105000449586 豫ICP备08007559号 最佳分辨率 1024*768
地址:郑州大学北校区院(文化路97号院)内