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

150 篇文章 0 订阅
19 篇文章 0 订阅

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

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

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

 

1.3 Your First Web Service in CGI

1.3 你的第一个CGI的 Web Service(程序)

Developing a service application is easy too.

开发一个服务应用也是容易的。

Suppose we implement a CGI-based service that returns the time in GMT. 

假定我们实现一个基于CGI的服务,它返回这个GMT时间。

The Common Gateway Interface (CGI) is a simple mechanism to publish services on your Web site, but it is certainly not the most efficient way. 

这个通用网关接口(GCI)是一个简单的机制去发布服务在你的站点,但是它是确定的不是最有效率的方式。

You can also develop high-performance stand-alone gSOAP services with built-in HTTP/S stacks or you can use Apache mod gsoap and IIS (see the extras directory).

你能开发高性能的单机的gSOAP服务用嵌入的 HTTP/S栈或者你能用Apache修改gsoapIIS(看附录)

Our currentTime service only has an output parameter, which is the current time:

我们的currentTime服务只有一个输出参数,就是当前时间:

 

// File: currentTime.h

//gsoap ns service name: currentTime

//gsoap ns service namespace: urn:currentTime

//gsoap ns service location: http://www.localhost.com/currentTime.cgi

int ns__currentTime(time_t& response);

 

Note that we must associate an XML namespace with a service. 

注意那是我们必须关联一个XML命名空间和一个服务。

The gSOAP tools use a special convention for identifier names that are part of a namespace: a namespace prefix (ns in this case) followed by a double underscore . 

这个gSOAP工具用一个特殊的规则去标识名称,命名空间的一部分:一个命名空间前缀(n)之后跟一个双下划线。

This convention is used to resolve namespaces and to avoid name clashes. 

这个规则是被用来解决命名空间和避免命名冲突。

The ns namespace prefix is bound to the urn:currentTime namespace name with the //gsoap directive.

这个ns命名空间前缀是限制到urn:currentTime 命名空间 名称用这个 //gsoap 指令。

The //gsoap directives are used to set the properties of the service, in this case the name, namespace, and location endpoint.

这个 //gsoap指令是被用来去设置服务属性,在这种情况下这种命名,名称空间,和定位点。

 

The service implementation for CGI is

这个服务CGI的安装启用是

 

// File: currentTime.cpp

main()

{

// create soap context and serve one CGI-based request:

soap serve(soap new());

}

int ns__currentTime(struct soap *soap, time_t& response)

{

response = time(0);

return SOAP_OK;

}

 

Note that we pass the soap struct with the gSOAP context information to the service routine, which can be handy to determine properties of the connection and to dynamically allocate data with soap_malloc(soap, num bytes) that will be automatically deleted when the service is finished.

注意:我们通过这个soap 结构和这个gSOAP上下文信息服务程序,能够方便的确定属性的连接和动态的分配数据用soap_malloc(soap, num bytes),当服务完成时它将自动的删除。

We run the soapcpp2 compiler on the header file to generate the server-side code:

我们运行这个soapcpp2编译器在一个头文件生成服务端代码:

$ soapcpp2 -S currentTime.h

nd then compile the CGI binary:

和编译这个CGI的二进制:

$ c++ -o currentTime.cgi currentTime.cpp soapC.cpp soapServer.cpp stdsoap2.cpp

 

 

To activate the service, copy the currentTime.cgi binary to your bin-cgi directory with the proper file permissions.

去激活服务,复制currentTime.cgi 二进制到你的 bin-cgi 目录和适当的文件权限。

 

The soapcpp2 compiler generated the WSDL definitions currentTime.wsdl. 

这个soapcpp2编译器生成的WSDL定义currentTime.wsdl

You can use the WSDL to advertize your service. 

你能有这个WSDL去通知你的服务。

You dont need to use this WSDL to develop a gSOAP client. 

你不需要去用这个WSDL去开发一个gSOAP客户端。

You can use the currentTime.h file with the soapcpp2 -C command to generate client-side code.

你能用这个currentTime.h 文件和soapcpp2 -C命令去生成客户端代码。

When you contribute a Web service with interesting capabilities, you can contact www.XMethods.com to publish your service and see it with the client application for the XMethods service listing you developed in the previous section.

当你的贡献一个Web service有令人感兴趣的功能,你能联系www.XMethods.com 去发布你的服务和看他用客户端应用在XMethod服务列出你开发的先前的部分。

 

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值