Nay Lin 顾问软件工程师,WebSphere Enablement Team IBM Customer Solutions Center,加利福尼亚圣地亚哥 2003 年 1 月
? Copyright International Business Machines Corporation 2003. All rights reserved. 引言
WebSphere? Studio Application Developer(以下称为 Application Developer)为快速从现有 J2EE 组件构建 SOAP/xml Web 提供向导,例如从会话 EJB 和 java? bean 组件来构建。Application Developer 能为任何 Java 客户机或 WSDL 文件生成一个 Java 客户机代理,只要这些文件能被其它供给商用来构建 Web 服务客户机。
某些情况下,您也许需要一个非 Java 客户机来使用 J2EE Web 服务。您可以使用 Microsoft? .NET 框架提供的 wsdl.exe 工具来为 WebSphere Web 服务生成一个 C# 或 Jscript 客户机。或者,一些开放源代码工具能为在不同语言和操作系统中生成客户机提供便利。(这里有 SOAP 软件工具清单)。
开放源代码工具之一的 gSOAP 提供一种独特的 SOAP/XML 到 C/C++ 语言绑定,以简化 C 或 C++ 中 SOAP/XML Web 服务和客户机的开发。gSOAP 工具包括一个 WSDL 生成器,用于为您的 Web 服务生成 Web 服务描述。WSDL importer 工具使 SOAP 客户机应用程序开发完全自动化。
使用 Application Developer 和 gSOAP 编译器、C/C++ 和 Fortran 下的客户机(经由一个 Fortran 连接到 C 接口)以及 4GL 客户机,例如 PowerBuilder(通过一个 C++ DLL),就能通过 WebSphere Application Server 跨平台连接作为 Web 服务公开的 J2EE 应用程序。
if (soap_call_tns__hello ( &soap, "http://localhost:8080/HelloWorldWebService/servlet/rpcrouter", "","Nay Lin", &response)== SOAP_OK) { cout << "HelloWorld WebService response "<<endl; cout << "result = "<< response._result <<endl; } else soap_print_fault(&soap,stderr); //display the SOAP fault message on the stderr stream
soap_end(&soap); //clean up cout <<"Press e to end program .." <<endl; cin >> dummy; return 0; }
示例头文件由 gSOAP 工具生成:
清单 6. HelloWorld-service.h
//gsoap tns schema namespace: http://tempuri.org/com.ibm.hello.ejb.HelloWorld //gsoap binding schema namespace: http://www.helloworld.com/definitions/HelloWorldRemoteInterface //gsoap tns service namespace: http://localhost:8080/HelloWorldWebService/wsdl/HelloWorld-service.wsdl //gsoap tns service location: http://localhost:8080/HelloWorldWebService/servlet/rpcrouter //gsoap tns service name: soapHelloWorldService /*start primitive data types*/ typedef char * xsd__string; /*end primitive data types*/ //soapAction : tns__hello ( xsd__string str, struct tns__helloResponse {xsd__string _result; } *out) ;
生成 Windows 控制台应用程序或 DLL
要编译并运行这些 C/C++ 程序,可以使用 GNU C++ 编译器或将 C/C++ 程序导入到 Visual C++ 6.0 中。要运行这里的 HelloWorld 示例,我们使用一种简单的 Windows 平台 Dev-C++ 上的 GNU C++ IDE。您可以从 SourceForge 或 BloodShed.net 下载。如需联机帮助,您还需要定购一张便宜的 CD,它容量较小(大约 10MB),而且简单。假如您编译运行 GNU 调试器,可能会使用太多内存,或许是因为您进入一个程序呼叫时,它都试图打开一个窗口。
图 1. DevC++ IDE。
gSOAP 模块 stdsoap2.cpp 的链接需要 wsock32.dll 库。要在 Visual C++ 6.0 中安装此项:
这些知识能帮助您从开始用 WebSphere Web 服务和开放源代码工具将 J2EE 企业应用程序和 C/C++ 应用程序集成起来。 相关信息
* Sheldon Wosnick 所写的 使用 WebSphere Studio Application Developer 开发并测试一段完整“Hello World”J2EE 应用程序 * Sheldon Wosnick 所写的 使用 WebSphere Studio Application Developer 开发并测试一段完整 J2EE 应用程序 — 第 2 部分:在 WebSphere Application Server 上运行 * Sheldon Wosnick 所写的 开发 IBM WebSphere Studio Application Developer 和 Microsoft .NET Framework SDK 支持的 Microsoft .NET Web Service Clients for EJB Web Services
* WebSphere Studio Application Developer Integration Edition -- Presentations 和 Labs * Robert A. van Engelen 所写的 The gSOAP Stub and Skeleton Compiler for C and C++ 2.1.7
关于作者 Nay Lin 加利福尼亚圣地亚哥 IBM WebSphere Enablement team 的顾问软件工程师。他的顾问专长包括 WebSphere Application Server、WebSphere 企业编程模型扩展和使用 WebSphere Studio Application Developer 的应用程序开发。您可以通过 naylin@us.ibm.com 与 Nay 联系。
IBM、DB2、VisualAge 和 WebSphere 是 IBM 公司在美国或其它国家或地区的商标或注册商标。
Microsoft、Windows、Windows NT 和 Windows 徽标是 Microsoft 公司在美国或其它国家或地区的商标或注册商标。
Java 和所有基于 Java 的商标与徽标都是 Sun Microsystems 公司在美国或其它国家或地区的商标或注册商标。