Web Services--gSOAP 2.7.6 第一章(1.2)

来源:互联网 发布:mac xdebug 安装 编辑:程序博客网 时间:2024/05/22 11:33

下载地址:http://sourceforge.net/projects/gsoap2

官方网站:http://genivia.com/Products/gsoap/index.html

本文翻译只是出于学习的目的,中文部分仅代表个人观点,有错误还望指正,英文部分来自gsoap-win32-2.7\doc\soapdoc2.pdf。其中复制可能有误,可以看懂英文的还请到官网下载。如有版权争议,请联系QQ:643166601,本人会及处理。翻译新手,有错是必然的,求高人指点。欢迎同为新手的你共同学习。

 

 

1.2 Your First Web Service Client Application

1.2 你的第一个 Web Service客户端程序 

The gSOAP tools minimize application adaptation efforts for building Web Services. 

这个gSOAP工具最小程序适应努力去构建Web Services

The gSOAP wsdl2h tool imports one or more WSDLs and XML schemas to generate a header file with the Web

service operations and the C/C++ data types used by the services. 

这个gSOAP的 wsdl2h工具导入一个或更多的WSDLs 和 XML schemas去产生一个头文件和这个Web

service 操作和被C/C++数据类型使用的服务。

The gSOAP soapcpp2 compiler takes the header file and generates XML serializers for the data types (soapH.h and soapC.cpp), the client-side stubs (soapClient.cpp), and server-side skeletons (soapServer.cpp).

这个gSOAPsoapcpp2编译器用这个头文件,生成XML序列化的树类型(soapH.h and soapC.cpp),这个客户端stubs(soapClient.cpp),和服务端skeletons (soapServer.cpp).

The gSOAP soapcpp2 compiler can also generate WSDL definitions for implementing a service from scratch, i.e. without defining a WSDL first. 

这个gSOAPsoapcpp2编译器也能产生WSDL实现定义一个服务从无到有等,除非首先定义一个WSDL

This closes the circle” in that it enables Web services development from WSDL or directly from a set op C/C++ operations in a header file without the need for users to analyze Web service details.

在这个“闭合环”中,它使能够Web services开发来自WSDL或直接来自一个设置C/C++操作的头文件,不需要用户的分析Web service细节。

You only need to follow a few steps to execute the tools from the command line or Makefile (see also MSVC++ project examples in the samples directory with tool integration in the MSVC++ IDE).

你只需要去跟着很少的步骤去执行这个工具来自这命令行或Makeflie(也看到 MSVC++项目程序在这个样本目录与MSVC++ IDE 工具结合)

For example, to generate code for the XMethods service listing Web service, we run the wsdl2h tool from the command line on the URL of the WSDL and use option -o to specify the output file:

例如,去生成XMethods 服务代码列出 Web service, 我们运行这个 wsdl2h 工具,从这个命令行在WSDLURL和用指定-o选项输出文件。

$ wsdl2h -o XMethodsQuery.h http://www.xmethods.net/wsdl/query.wsdl

 

 

This generates the XMethodsQuery.h header file with Web service operations and the data types that the service uses. 

这个生成的XMethodsQuery.h头文件及Web service操作和这个数据类型,这个服务使用的。

This header file is to be processed with soapcpp2 to generate the stub and/or skeleton code. 

这个头文件是被soapcpp2加工过的去生成stub/或 skeleton代码。

The XMethodsQuery.h file includes all documentation, so you can use Doxygen (http://www.doxygen.org) to automatically generate the documentation pages for your development.

这个XMethodsQuery.h文件包含所有的参考资料,因此你可以用Doxygen(http://www.doxygen.org), 自动生成你的开发的参考资料页。

In this example we are developing a C++ API for the XMethods service. 

在这个例子,我们开发一个C++API的 XMethods 服务。

By default, gSOAP assumes you will use C++ with STL. To build without STL, use option -s:

默认情况,gSOAP假定你将要用C++STL。去建立没有STL,用选项-s

 

 

$ wsdl2h -s -o XMethodsQuery.h http://www.xmethods.net/wsdl/query.wsdl

 

To build a pure C application, use option -c:

去建立一个纯C的应用,用选项-c

 

$ wsdl2h -c -o XMethodsQuery.h http://www.xmethods.net/wsdl/query.wsdl

 

We have not yet generated the stubs for the C/C++ API. To do so, run the soapcpp2 compiler:

我们没有生成这个C/C++ APIstubs。要这样做,运行soapcpp2编译器:

$ soapcpp2 -C -Iimport XMethodsQuery.h

 

Where option -C indicates client-side only files (soapcpp2 generates both client and server stubs and

skeletons by default). 

那里选项-C只是只有客户端文件(soapcpp2默认生成客户端和服务端的stubsskeletons)

Option -I is needed to import the stlvector.h file to support STL vectors.

选项 -I 是被需要去导入这个stlvector.h去支持STLvectors

Suppose we develop a C++ client for the XMethods service. 

假设我们开发的XMethods服务的一个C++客户端。

In this case we use the generated soapXMethodsQuerySoapProxy class and XMethodsQuerySoap.nsmap XML namespace mapping table to access the Web service. 

既然这样我们用生成的soapXMethodsQuerySoapProxy类和XMethodsQuerySoap.nsmap XML命名空间映射表去访问这个Web service

The soapXMethodsQuerySoapProxy class is a proxy to invoke the service:

这个soapXMethodsQuerySoapProxy类是一个代理去回收这个服务:

 

 

#include soapXMethodsQuerySoapProxy.h

#include XMethodsQuerySoap.nsmap

main()

{

XMethodsQuerySoap service;

ns3 getAllServiceNamesResponse response;

// get all service names from the XMethods database:

if (service.ns3 getAllServiceNames(response) == SOAP OK)

std::cout << The first XMethods service is: ” << (*response. Result-> ptr[0]->name) <<

std::endl;

else

soap print fault(service.soap, stderr);

}

 

The response data structure is defined in XMethodsQuery.h, and contains a SOAP encoded array ( ptr[n]) of pointers to ID-Name pairs ( ptr[n]->id and ptr[n]->name). 

这个反映数据结构是定义在XMethodsQuery.h中。包含一个SOAP编码数组(ptr[n])的指针到ID-Name pairs(ptr[n]->id 和 ptr[n]->name)

(Note: you may want to add NULL checks before dereferencing the pointers.) 

(注意:你想要去增加NULL check之前取消引用的指针。)

To complete the build, compile and link the generated soapC.cpp, soapClient.cpp, and the run-time gSOAP engine stdsoap2.cpp with your code.

去完成这个构建,用你的代码编译和连接生成soapC.cpp, soapClient.cpp和运行时gSOAP引擎stdsoap2.cpp 

原创粉丝点击