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,它容量較?。ù蠹s 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 公司在美國或其它國家或地區的商標或注冊商標。