📄 1054.html
字号:
</operation><br>
</binding><br>
<service name="HelloWorldService"><br>
<port binding="binding:HelloWorldBinding" name="HelloWorldPort"><br>
<soap:address location="http://localhost:8080/HelloWorldWebService/servlet/rpcrouter"/><br>
</port><br>
</service> <br>
</definitions><br>
<br>
上面的样本 WSDL 文件(以及所包含的 EAR 文件)是由 Application Developer 4.02 所生成。这里的说明适用于 Application Developer 5.0 生成的 Web 服务,只要对 <import ../> 作一致修改。<br>
生成 C/C++ 组件和一个客户机<br>
<br>
从 WSDL 新建代理(存根)需要两个步骤(参见 C:soapcpp-win32-2.1.7wsdlcppREADME.txt 中说明的第 2 步)。<br>
<br>
1. 执行 Java 程序 wsdlcpp(WSDL Importer):java wsdlcpp <file>.wsdl。这将生成以下文件:<br>
<file>.h gSOAP 编译器的头文件声明<br>
<file>.c 一个客户机程序摸板<br>
<br>
这里 <file> 是输入 WSDL 文件的名称。头文件将由 gSOAP 编译器处理:<br>
2. 执行 gSOAP 编译器:soapcpp2 <file>.h<br>
<br>
这将生成以下组件:<br>
soapStub.h 与 <file>.h 相似的头文件,但带有数据类型注释<br>
soapH.h soapC.cpp 的头文件<br>
soapC.cpp C/C++ 数据类型的 SOAP/XML(反)序列化器<br>
soapClient.cpp 远程方法调用的代理存根例程<br>
soapServer.cpp 服务执行的框架例程<br>
soap<srv>.wsdl 一个 WSDL 文件,<srv>是服务名<br>
<srv>.nsmap 客户机应用程序的一个名称空间映射表<br>
<br>
定制主要的 C/C++ 客户机(生成为 <file>.c)<br>
<br>
修改生成的客户机以声明合适的输入和输出变量,并将这些作为参数传递给 Web 服务方法调用。您可能还想将此文件重命名为 .cpp。由于要和 C 语言兼容,返回类型定义为 struct(在 soapStub.h 中定义)。在我们的示例中,定义如下:<br>
<br>
清单 4. 返回类型定义<br>
<br>
struct tns__helloResponse<br>
{<br>
char *_result;<br>
};<br>
<br>
这是此工具生成的样本客户机代码 HelloWorld-service.cpp,然后进行修改(您可以将输入名称 Nay Lin 修改为您自己的名字)。<br>
<br>
清单 5. HelloWorld-service.cpp<br>
<br>
#include "soapH.h"<br>
#include "soapHelloWorldService.nsmap"<br>
#include <iostream.h><br>
main()<br>
{<br>
struct soap soap; // gSOAP runtime environment<br>
soap_init(&soap); // initialize runtime environment (only once)<br>
struct tns__helloResponse response;<br>
char dummy[100];<br>
<br>
if (soap_call_tns__hello ( &soap, "http://localhost:8080/HelloWorldWebService/servlet/rpcrouter",<br>
"","Nay Lin", &response)== SOAP_OK)<br>
{<br>
cout << "HelloWorld WebService response "<<endl;<br>
cout << "result = "<< response._result <<endl;<br>
}<br>
else<br>
soap_print_fault(&soap,stderr); //display the SOAP fault message on the stderr stream<br>
<br>
soap_end(&soap); //clean up<br>
cout <<"Press e to end program .." <<endl;<br>
cin >> dummy;<br>
return 0;<br>
}<br>
<br>
示例头文件由 gSOAP 工具生成:<br>
<br>
清单 6. HelloWorld-service.h<br>
<br>
//gsoap tns schema namespace: http://tempuri.org/com.ibm.hello.ejb.HelloWorld<br>
//gsoap binding schema namespace: http://www.helloworld.com/definitions/HelloWorldRemoteInterface<br>
//gsoap tns service namespace: http://localhost:8080/HelloWorldWebService/wsdl/HelloWorld-service.wsdl<br>
//gsoap tns service location: http://localhost:8080/HelloWorldWebService/servlet/rpcrouter<br>
//gsoap tns service name: soapHelloWorldService<br>
/*start primitive data types*/<br>
typedef char * xsd__string;<br>
/*end primitive data types*/<br>
//soapAction :<br>
tns__hello ( xsd__string str, struct tns__helloResponse {xsd__string _result; } *out) ;<br>
<br>
生成 Windows 控制台应用程序或 DLL<br>
<br>
要编译并运行这些 C/C++ 程序,可以使用 GNU C++ 编译器或将 C/C++ 程序导入到 Visual C++ 6.0 中。要运行这里的 HelloWorld 示例,我们使用一种简单的 Windows 平台 Dev-C++ 上的 GNU C++ IDE。您可以从 SourceForge 或 BloodShed.net 下载。如需联机帮助,您还需要定购一张便宜的 CD,它容量较小(大约 10MB),而且简单。如果您编译运行 GNU 调试器,可能会使用太多内存,或许是因为您进入一个程序呼叫时,它都试图打开一个窗口。<br>
<br>
图 1. DevC++ IDE。<br>
<br>
gSOAP 模块 stdsoap2.cpp 的链接需要 wsock32.dll 库。要在 Visual C++ 6.0 中安装此项:<br>
<br>
1. 选择 File view 中的 project file,选择 Project => Settings,然后选择 Link 选项卡。<br>
2. 将 wsock32.lib 添加到 Object/library 模块条目。要在 Dev-C++ 中添加,右键单击您的项目并选择 Project options。打开了 Project options 窗口。<br>
3. 在 Linker Options/Optional Libs 或 Object files 区域,输入 -lwsock32。<br>
<br>
您可以选择 Type WIN32 DLL 项目以生成一个 DLL 而不是 Dev-C++ 下的可执行文件。这是 Dev-C++ IDE Project Options 窗口的抓屏:<br>
<br>
图 2. 配置 project options。<br>
<br>
推荐:取消对 stdsoap.h 中下列行的注释,以打开 logging in the beginning 功能:<br>
<br>
#define DEBUG */ /* Uncomment to debug sending (in file SENT.log) receiving (in file RECV.log)<br>
and messages (in file TEST.log)<br>
<br>
这样会在项目工作目录下生成 log 文件。这里有样本控制台输出,是由为访问 HelloWorld Web 服务而运行 C++ 客户机应用程序所生成的:<br>
<br>
HelloWorld WebService response<br>
result = HelloWorld From Nay Lin!<br>
Press e to end program .. <br>
<br>
结束语<br>
<br>
本文演示了如何使用开放源代码工具 gSOAP 和 Dev-Cpp 来开发一个连接到 WebSphere Web 服务的 C/C++ 客户机。您已经学习了如何:<br>
<br>
* 下载、安装和配置 gSOAP 以及 gSOAP Importer 工具。<br>
* 从 Application developer 所生成的两个 WSDL 文件来准备一个 WSDL 文件。<br>
* 生成并定制 C/C++ 客户机组件。<br>
* 使用开放源代码 IDE Dev-C++ 生成一个 Windows 控制台应用程序或 DLL。<br>
<br>
这些知识能帮助您从开始用 WebSphere Web 服务和开放源代码工具将 J2EE 企业应用程序和 C/C++ 应用程序集成起来。<br>
相关信息<br>
<br>
* Sheldon Wosnick 所写的 使用 WebSphere Studio Application Developer 开发并测试一段完整“Hello World”J2EE 应用程序<br>
* Sheldon Wosnick 所写的 使用 WebSphere Studio Application Developer 开发并测试一段完整 J2EE 应用程序 — 第 2 部分:在 WebSphere Application Server 上运行<br>
* Sheldon Wosnick 所写的 开发 IBM WebSphere Studio Application Developer 和 Microsoft .NET Framework SDK 支持的 Microsoft .NET Web Service Clients for EJB Web Services<br>
* WebSphere Studio Application Developer Integration Edition -- Presentations 和 Labs<br>
* Robert A. van Engelen 所写的 The gSOAP Stub and Skeleton Compiler for C and C++ 2.1.7<br>
<br>
关于作者<br>
Nay Lin 加利福尼亚圣地亚哥 IBM WebSphere Enablement team 的顾问软件工程师。他的顾问专长包括 WebSphere Application Server、WebSphere 企业编程模型扩展和使用 WebSphere Studio Application Developer 的应用程序开发。您可以通过 naylin@us.ibm.com 与 Nay 联系。<br>
<br>
IBM、DB2、VisualAge 和 WebSphere 是 IBM 公司在美国或其它国家或地区的商标或注册商标。<br>
<br>
Microsoft、Windows、Windows NT 和 Windows 徽标是 Microsoft 公司在美国或其它国家或地区的商标或注册商标。<br>
<br>
Java 和所有基于 Java 的商标与徽标都是 Sun Microsystems 公司在美国或其它国家或地区的商标或注册商标。<br>
<br>
其它公司、产品和服务名称可能是其它公司的商标或服务标志。
</FONT><br>
</TD>
</TR>
<TR>
<TD colSpan=2><FONT
class=middlefont></FONT><BR>
<FONT
class=normalfont>全文结束</FONT> </TD>
</TR>
<TR>
<TD background="images/dot.gif" tppabs="http://www.linuxhero.com/docs/images/dot.gif" colSpan=2
height=10></TD></TR></TBODY></TABLE></TD></TR></TBODY></TABLE></DIV></TD>
<TD vAlign=top width="20%"
background="images/line.gif" tppabs="http://www.linuxhero.com/docs/images/line.gif" rowSpan=2>
<DIV align=center>
<table class=tableoutline cellspacing=1 cellpadding=4
width="100%" align=center border=0>
<tr class=firstalt>
<td noWrap background="images/bgline.gif" tppabs="http://www.linuxhero.com/docs/images/bgline.gif" colspan=2 height=21>
<font class=normalfont><b>所有分类</b></font></td>
</tr>
<tr class=secondalt> <td noWrap width=27%> <font class=normalfont>1:</font> </td><td noWrap width=73%> <table width=100% border=0> <tr> <td><font class=normalfont><a href="type1.html" tppabs="http://www.linuxhero.com/docs/type1.html">非技术类</a></font></td> </tr> </table></td></tr><tr class=firstalt> <td noWrap width=27%> <font class=normalfont>2:</font> </td><td noWrap width=73%> <table width=100% border=0> <tr> <td><font class=normalfont><a href="type2.html" tppabs="http://www.linuxhero.com/docs/type2.html">基础知识</a></font></td> </tr> </table></td></tr><tr class=secondalt> <td noWrap width=27%> <font class=normalfont>3:</font> </td><td noWrap width=73%> <table width=100% border=0> <tr> <td><font class=normalfont><a href="type3.html" tppabs="http://www.linuxhero.com/docs/type3.html">指令大全</a></font></td> </tr> </table></td></tr><tr class=firstalt> <td noWrap width=27%> <font class=normalfont>4:</font> </td><td noWrap width=73%> <table width=100% border=0> <tr> <td><font class=normalfont><a href="type4.html" tppabs="http://www.linuxhero.com/docs/type4.html">shell</a></font></td> </tr> </table></td></tr><tr class=secondalt> <td noWrap width=27%> <font class=normalfont>5:</font> </td><td noWrap width=73%> <table width=100% border=0> <tr> <td><font class=normalfont><a href="type5.html" tppabs="http://www.linuxhero.com/docs/type5.html">安装启动</a></font></td> </tr> </table></td></tr><tr class=firstalt> <td noWrap width=27%> <font class=normalfont>6:</font> </td><td noWrap width=73%> <table width=100% border=0> <tr> <td><font class=normalfont><a href="type6.html" tppabs="http://www.linuxhero.com/docs/type6.html">xwindow</a></font></td> </tr> </table></td></tr><tr class=secondalt> <td noWrap width=27%> <font class=normalfont>7:</font> </td><td noWrap width=73%> <table width=100% border=0> <tr> <td><font class=normalfont><a href="type7.html" tppabs="http://www.linuxhero.com/docs/type7.html">kde</a></font></td> </tr> </table></td></tr><tr class=firstalt> <td noWrap width=27%> <font class=normalfont>8:</font> </td><td noWrap width=73%> <table width=100% border=0> <tr> <td><font class=normalfont><a href="type8.html" tppabs="http://www.linuxhero.com/docs/type8.html">gnome</a></font></td> </tr> </table></td></tr><tr class=secondalt> <td noWrap width=27%> <font class=normalfont>9:</font> </td><td noWrap width=73%> <table width=100% border=0> <tr> <td><font class=normalfont><a href="type9.html" tppabs="http://www.linuxhero.com/docs/type9.html">输入法类</a></font></td> </tr> </table></td></tr><tr class=firstalt> <td noWrap width=27%> <font class=normalfont>10:</font> </td><td noWrap width=73%> <table width=100% border=0> <tr> <td><font class=normalfont><a href="type10.html" tppabs="http://www.linuxhero.com/docs/type10.html">美化汉化</a></font></td> </tr> </table></td></tr><tr class=secondalt> <td noWrap width=27%> <font class=normalfont>11:</font> </td><td noWrap width=73%> <table width=100% border=0> <tr> <td><font class=normalfont><a href="type11.html" tppabs="http://www.linuxhero.com/docs/type11.html">网络配置</a></font></td> </tr> </table></td></tr><tr class=firstalt> <td noWrap width=27%> <font class=normalfont>12:</font> </td><td noWrap width=73%> <table width=100% border=0> <tr> <td><font class=normalfont><a href="type12.html" tppabs="http://www.linuxhero.com/docs/type12.html">存储备份</a></font></td> </tr> </table></td></tr><tr class=secondalt> <td noWrap width=27%> <font class=normalfont>13:</font> </td><td noWrap width=73%> <table width=100% border=0> <tr> <td><font class=normalfont><a href="type13.html" tppabs="http://www.linuxhero.com/docs/type13.html">杂项工具</a></font></td> </tr> </table></td></tr><tr class=firstalt> <td noWrap width=27%> <font class=normalfont>14:</font> </td><td noWrap width=73%> <table width=100% border=0> <tr> <td><font class=normalfont><a href="type14.html" tppabs="http://www.linuxhero.com/docs/type14.html">编程技术</a></font></td> </tr> </table></td></tr><tr class=secondalt> <td noWrap width=27%> <font class=normalfont>15:</font> </td><td noWrap width=73%> <table width=100% border=0> <tr> <td><font class=normalfont><a href="type15.html" tppabs="http://www.linuxhero.com/docs/type15.html">网络安全</a></font></td> </tr> </table></td></tr><tr class=firstalt> <td noWrap width=27%> <font class=normalfont>16:</font> </td><td noWrap width=73%> <table width=100% border=0> <tr> <td><font class=normalfont><a href="type16.html" tppabs="http://www.linuxhero.com/docs/type16.html">内核技术</a></font></td> </tr> </table></td></tr><tr class=secondalt> <td noWrap width=27%> <font class=normalfont>17:</font> </td><td noWrap width=73%> <table width=100% border=0> <tr> <td><font class=normalfont><a href="type17.html" tppabs="http://www.linuxhero.com/docs/type17.html">速度优化</a></font></td> </tr> </table></td></tr><tr class=firstalt> <td noWrap width=27%> <font class=normalfont>18:</font> </td><td noWrap width=73%> <table width=100% border=0> <tr> <td><font class=normalfont><a href="type18.html" tppabs="http://www.linuxhero.com/docs/type18.html">apache</a></font></td> </tr> </table></td></tr><tr class=secondalt> <td noWrap width=27%> <font class=normalfont>19:</font> </td><td noWrap width=73%> <table width=100% border=0> <tr> <td><font class=normalfont><a href="type19.html" tppabs="http://www.linuxhero.com/docs/type19.html">email</a></font></td> </tr> </table></td></tr><tr class=firstalt> <td noWrap width=27%> <font class=normalfont>20:</font> </td><td noWrap width=73%> <table width=100% border=0> <tr> <td><font class=normalfont><a href="type20.html" tppabs="http://www.linuxhero.com/docs/type20.html">ftp服务</a></font></td> </tr> </table></td></tr><tr class=secondalt> <td noWrap width=27%> <font class=normalfont>21:</font> </td><td noWrap width=73%> <table width=100% border=0> <tr> <td><font class=normalfont><a href="type21.html" tppabs="http://www.linuxhero.com/docs/type21.html">cvs服务</a></font></td> </tr> </table></td></tr><tr class=firstalt> <td noWrap width=27%> <font class=normalfont>22:</font> </td><td noWrap width=73%> <table width=100% border=0> <tr> <td><font class=normalfont><a href="type22.html" tppabs="http://www.linuxhero.com/docs/type22.html">代理服务</a></font></td> </tr> </table></td></tr><tr class=secondalt> <td noWrap width=27%> <font class=normalfont>23:</font> </td><td noWrap width=73%> <table width=100% border=0> <tr> <td><font class=normalfont><a href="type23.html" tppabs="http://www.linuxhero.com/docs/type23.html">samba</a></font></td> </tr> </table></td></tr><tr class=firstalt> <td noWrap width=27%> <font class=normalfont>24:</font> </td><td noWrap width=73%> <table width=100% border=0> <tr> <td><font class=normalfont><a href="type24.html" tppabs="http://www.linuxhero.com/docs/type24.html">域名服务</a></font></td> </tr> </table></td></tr><tr class=secondalt> <td noWrap width=27%> <font class=normalfont>25:</font> </td><td noWrap width=73%> <table width=100% border=0> <tr> <td><font class=normalfont><a href="type25.html" tppabs="http://www.linuxhero.com/docs/type25.html">网络过滤</a></font></td> </tr> </table></td></tr><tr class=firstalt> <td noWrap width=27%> <font class=normalfont>26:</font> </td><td noWrap width=73%> <table width=100% border=0> <tr> <td><font class=normalfont><a href="type26.html" tppabs="http://www.linuxhero.com/docs/type26.html">其他服务</a></font></td> </tr> </table></td></tr><tr class=secondalt> <td noWrap width=27%> <font class=normalfont>27:</font> </td><td noWrap width=73%> <table width=100% border=0> <tr> <td><font class=normalfont><a href="type27.html" tppabs="http://www.linuxhero.com/docs/type27.html">nfs</a></font></td> </tr> </table></td></tr><tr class=firstalt> <td noWrap width=27%> <font class=normalfont>28:</font> </td><td noWrap width=73%> <table width=100% border=0> <tr> <td><font class=normalfont><a href="type28.html" tppabs="http://www.linuxhero.com/docs/type28.html">oracle</a></font></td> </tr> </table></td></tr><tr class=secondalt> <td noWrap width=27%> <font class=normalfont>29:</font> </td><td noWrap width=73%> <table width=100% border=0> <tr> <td><font class=normalfont><a href="type29.html" tppabs="http://www.linuxhero.com/docs/type29.html">dhcp</a></font></td> </tr> </table></td></tr><tr class=firstalt> <td noWrap width=27%> <font class=normalfont>30:</font> </td><td noWrap width=73%> <table width=100% border=0> <tr> <td><font class=normalfont><a href="type30.html" tppabs="http://www.linuxhero.com/docs/type30.html">mysql</a></font></td> </tr> </table></td></tr><tr class=secondalt> <td noWrap width=27%> <font class=normalfont>31:</font> </td><td noWrap width=73%> <table width=100% border=0> <tr> <td><font class=normalfont><a href="type31.html" tppabs="http://www.linuxhero.com/docs/type31.html">php</a></font></td> </tr> </table></td></tr><tr class=firstalt> <td noWrap width=27%> <font class=normalfont>32:</font> </td><td noWrap width=73%> <table width=100% border=0> <tr> <td><font class=normalfont><a href="type32.html" tppabs="http://www.linuxhero.com/docs/type32.html">ldap</a></font></td> </tr> </table></td></tr> </table>
</DIV></TD></TR>
<TR vAlign=top>
<TD width="80%">
<DIV align=center><BR>
</DIV>
</TD></TR></TBODY></TABLE></TD></TR>
</TABLE></TD></TR>
</TABLE>
<TABLE cellSpacing=0 cellPadding=4 width="100%" bgColor=#eeeeee
border=0><TBODY>
<TR>
<TD width="50%">
<P><FONT class=middlefont>版权所有 © 2004 <A
href="mailto:bjchenxu@sina.com">linux知识宝库</A><BR>
违者必究. </FONT></P>
</TD>
<TD width="50%">
<DIV align=right><FONT class=middlefont>Powered by: <A
href="mailto:bjchenxu@sina.com">Linux知识宝库</A> Version 0.9.0 </FONT></DIV>
</TD></TR></TBODY></TABLE>
<CENTER></CENTER></TD></TR>
</TABLE></CENTER></BODY></HTML>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -