国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 學院 > 開發設計 > 正文

websphere新建C/C++客戶機

2019-11-17 05:14:53
字體:
來源:轉載
供稿:網友

  使用WebSphere Studio application Developer、gSOAP和Dev-C++為WebSphere Web服務新建一個C/C++客戶機
內容
引言
下載并安裝 gSOAP 工具
安裝 gSOAP WSDL importer 工具
預備一個輸入 WSDL 文件
生成 C/C++ 組件和一個客戶機
定制主要的 C/C++ 客戶機
生成 Windows 控制臺應用程序或 DLL
結束語

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 應用程序。

為相應的 J2EE Web 服務生成一個 C/C++ 客戶機:

1. 使用 Application Developer 生成 Web 服務及其 WSDL 文件,以公開一個 EJB 或 Java bean。
2. 在分布式平臺上的 WebSphere 4.0x/5.0 或 z/OS? 和 OS/390? 上的 WebSphere 4.01 上部署 Web 服務。
3. 使用 gSOAP WSDL importer 工具生成一個 C/C++ 客戶機應用程序或 DLL。本教程描述了如何運行第 3 步,假定第 1 步和第 2 步已完成。可在本頁下方下載為 Web 服務而從 Application Developer 4.02 生成并導出的名為 HelloWorld.ear 的樣本企業歸檔(enterPRise archive,EAR)文件。關于第 1 步和第 2 步的具體情況,參見 Application Developer 的聯機幫助或在相關信息中列出的關于使用 Application Developer 生成 Web 服務的教程和紅皮書。

下載并安裝 gSOAP 工具

進入 SourceForge 網站并(對于 Windows? 工作站)下載名為 soapcpp-win32-2.1.7.zip 的 ZIP 文件。將所有文件解壓縮到安裝盤(比如 C:)。如要測試 gSOAP 示例和 SSL,請按照 C:soapcpp-win32-2.1.7INSTALL.txt 里的說明。
安裝 gSOAP WSDL importer 工具

1. 切換到 C:soapcpp-win32-2.1.7wsdlcpp 目錄,閱讀 readme.txt 中關于第 1 步的說明。

2. 安裝一個用于 Java 的 XML 解析器,例如 Apache Xerces 2.0.1(xercesImpl.jar 和 xmlParserAPIs.jar)或 Xerces 1.4.4(xerces.jar)。可根據需要改變類路徑。WSDL 導入工具的 wsdlcpp.java 資源已為 Xerces DOM 解析器配置好了。如要使用另一個 Java DOM 解析器,請在 wsdlcpp.java 中修改 DOM 解析器類導入。
3. 使用 javac wsdlcpp.java 命令編譯 wsdlcpp。

預備一個輸入 WSDL 文件

此工具并不支持 <import../> 標記。這個輸入 WSDL 文件一定要是獨立的(參見 C:soapcpp- win32-2.1.7wsdlcppREADME.txt 文件中 Limitations 下的說明)。Application Developer 或 Application Developer Integration Edition 為每個 Web 服務 EAR 生成兩個名為 <wsname> 的 WSDL 文件(比如 <wsname>-service.wsdl 和 <wsname>-binding.wsdl)。第一個文件 <wsname>-service.wsdl 導入綁定的定義 <wsname>-binding.wsdl。要將它們合并到一個文件中:

1. 復制 <wsname>-binding.wsdl 中 <definitions>...</definitions> 里的所有元素條目。
2. 編輯 <wsname>-service.wsdl,將條目 <import ../> 用上面復制的內容覆蓋。

此處的示例是 Application Developer 為作為 Web 服務公開的 HellowWorld 會話 EJB 的 hello 方法而生成的兩個 WSDL 文件:

清單 1.HelloWorld-service.wsdl

<definitions name="HelloWorldService"
targetNamespace="http://localhost:8080/HelloWorldWebService/wsdl/HelloWorld-service.wsdl"
xmlns="http://schemas.xmlsoap.org/wsdl/"
xmlns:binding="http://www.helloworld.com/definitions/HelloWorldRemoteInterface"
xmlns:soap=http://schemas.xmlsoap.org/wsdl/soap/
xmlns:tns="http://localhost:8080/HelloWorldWebService/wsdl/HelloWorld-service.wsdl">
<import location="http://localhost:8080/HelloWorldWebService/wsdl/HelloWorld-binding.wsdl"
namespace="http://www.helloworld.com/definitions/HelloWorldRemoteInterface"/>
<service name="HelloWorldService">
<port binding="binding:HelloWorldBinding" name="HelloWorldPort">
<soap:address location="http://localhost:8080/HelloWorldWebService/servlet/rpcrouter"/>
</port>
</service>
</definitions>

清單 2.HelloWorld-binding.wsdl

<definitions name="HelloWorld-binding"
targetNamespace="http://www.helloworld.com/definitions/HelloWorldRemoteInterface"
xmlns="http://schemas.xmlsoap.org/wsdl/"
xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"
xmlns:tns=http://www.helloworld.com/definitions/HelloWorldRemoteInterface
xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<message name="helloRequest">
<part name="str" type="xsd:string"/>
</message>
<message name="helloResponse">
<part name="result" type="xsd:string"/>
</message>
<portType name="HelloWorld">
<Operation name="hello" parameterOrder="str">
<input message="tns:helloRequest" name="helloRequest"/>
<output message="tns:helloResponse" name="helloResponse"/>

</operation>
</portType>
<binding name="HelloWorldBinding" type="tns:HelloWorld">
<soap:binding style="rpc" transport="http://schemas.xmlsoap.org/soap/http"/>
<operation name="hello">
<soap:operation soapAction="" style="rpc"/>
<input name="helloRequest">
<soap:body
encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"
namespace="http://tempuri.org/com.ibm.hello.ejb.HelloWorld" use="encoded"/>
</input>
<output name="helloResponse">
<soap:body
encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"
namespace="http://tempuri.org/com.ibm.hello.ejb.HelloWorld" use="encoded"/>
</output>
</operation>
</binding>
</definitions>

這是合并后的 HelloWorld-service.wsdl WSDL 文件樣本:

清單 3. HelloWorld-service.wsdl

<definitions name="HelloWorldService"
targetNamespace="http://localhost:8080/HelloWorldWebService/wsdl/HelloWorld-service.wsdl"
xmlns="http://schemas.xmlsoap.org/wsdl/"
xmlns:binding="http://www.helloworld.com/definitions/HelloWorldRemoteInterface"
xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"
xmlns:tns=http://localhost:8080/HelloWorldWebService/wsdl/HelloWorld-service.wsdl
xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<message name="helloRequest">
<part name="str" type="xsd:string"/>
</message>
<message name="helloResponse">
<part name="result" type="xsd:string"/>
</message>
<portType name="HelloWorld">
<operation name="hello" parameterOrder="str">
<input message="tns:helloRequest" name="helloRequest"/>
<output message="tns:helloResponse" name="helloResponse"/>
</operation>
</portType>
<binding name="HelloWorldBinding" type="tns:HelloWorld">
<soap:binding style="rpc" transport="http://schemas.xmlsoap.org/soap/http"/>
<operation name="hello">
<soap:operation soapAction="" style="rpc"/>
<input name="helloRequest">
<soap:body
encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"
namespace=http://tempuri.org/com.ibm.hello.ejb.HelloWorld use="encoded"/>
</input>

<output name="helloResponse">
<soap:body
encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"
namespace="http://tempuri.org/com.ibm.hello.ejb.HelloWorld" use="encoded"/>
</output>
</operation>
</binding>
<service name="HelloWorldService">
<port binding="binding:HelloWorldBinding" name="HelloWorldPort">
<soap:address location="http://localhost:8080/HelloWorldWebService/servlet/rpcrouter"/>
</port>
</service>
</definitions>

上面的樣本 WSDL 文件(以及所包含的 EAR 文件)是由 Application Developer 4.02 所生成。這里的說明適用于 Application Developer 5.0 生成的 Web 服務,只要對 <import ../> 作一致修改。
生成 C/C++ 組件和一個客戶機

從 WSDL 新建代理(存根)需要兩個步驟(參見 C:soapcpp-win32-2.1.7wsdlcppREADME.txt 中說明的第 2 步)。

1. 執行 Java 程序 wsdlcpp(WSDL Importer):java wsdlcpp <file>.wsdl。這將生成以下文件:
<file>.h gSOAP 編譯器的頭文件聲明
<file>.c 一個客戶機程序摸板

這里 <file> 是輸入 WSDL 文件的名稱。頭文件將由 gSOAP 編譯器處理:
2. 執行 gSOAP 編譯器:soapcpp2 <file>.h

這將生成以下組件:
soapStub.h 與 <file>.h 相似的頭文件,但帶有數據類型注釋
soapH.h soapC.cpp 的頭文件
soapC.cpp C/C++ 數據類型的 SOAP/XML(反)序列化器
soapClient.cpp 遠程方法調用的代理存根例程
soapServer.cpp 服務執行的框架例程
soap<srv>.wsdl 一個 WSDL 文件,<srv>是服務名
<srv>.nsmap 客戶機應用程序的一個名稱空間映射表

定制主要的 C/C++ 客戶機(生成為 <file>.c)

修改生成的客戶機以聲明合適的輸入和輸出變量,并將這些作為參數傳遞給 Web 服務方法調用。您可能還想將此文件重命名為 .cpp。由于要和 C 語言兼容,返回類型定義為 strUCt(在 soapStub.h 中定義)。在我們的示例中,定義如下:

清單 4. 返回類型定義

struct tns__helloResponse
{
char *_result;
};

這是此工具生成的樣本客戶機代碼 HelloWorld-service.cpp,然后進行修改(您可以將輸入名稱 Nay Lin 修改為您自己的名字)。

清單 5. HelloWorld-service.cpp

#include "soapH.h"
#include "soapHelloWorldService.nsmap"
#include <iostream.h>
main()
{
struct soap soap; // gSOAP runtime environment
soap_init(&soap); // initialize runtime environment (only once)
struct tns__helloResponse response;
char dummy[100];

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 中安裝此項:

1. 選擇 File view 中的 project file,選擇 Project => Settings,然后選擇 Link 選項卡。
2. 將 wsock32.lib 添加到 Object/library 模塊條目。要在 Dev-C++ 中添加,右鍵單擊您的項目并選擇 Project options。打開了 Project options 窗口。
3. 在 Linker Options/Optional Libs 或 Object files 區域,輸入 -lwsock32。

您可以選擇 Type WIN32 DLL 項目以生成一個 DLL 而不是 Dev-C++ 下的可執行文件。這是 Dev-C++ IDE Project Options 窗口的抓屏:

圖 2. 配置 project options。

推薦:取消對 stdsoap.h 中下列行的注釋,以打開 logging in the beginning 功能:

#define DEBUG */ /* Uncomment to debug sending (in file SENT.log) receiving (in file RECV.log)
and messages (in file TEST.log)

這樣會在項目工作目錄下生成 log 文件。這里有樣本控制臺輸出,是由為訪問 HelloWorld Web 服務而運行 C++ 客戶機應用程序所生成的:

HelloWorld WebService response
result = HelloWorld From Nay Lin!
Press e to end program ..

結束語

本文演示了如何使用開放源代碼工具 gSOAP 和 Dev-Cpp 來開發一個連接到 WebSphere Web 服務的 C/C++ 客戶機。您已經學習了如何:

* 下載、安裝和配置 gSOAP 以及 gSOAP Importer 工具。
* 從 Application developer 所生成的兩個 WSDL 文件來預備一個 WSDL 文件。
* 生成并定制 C/C++ 客戶機組件。
* 使用開放源代碼 IDE Dev-C++ 生成一個 Windows 控制臺應用程序或 DLL。

這些知識能幫助您從開始用 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 公司在美國或其它國家或地區的商標或注冊商標。

其它公司、產品和服務名稱可能是其它公司的商標或服務標志。

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 福海县| 民乐县| 汶川县| 岑溪市| 保亭| 镇原县| 林芝县| 老河口市| 大同县| 福泉市| 南丰县| 湛江市| 兴山县| 天水市| 濮阳县| 桐柏县| 师宗县| 永嘉县| 哈密市| 镇远县| 禹城市| 卓尼县| 三河市| 清水河县| 成安县| 南靖县| SHOW| 龙海市| 凤冈县| 博爱县| 乐安县| 勐海县| 东莞市| 华坪县| 溧阳市| 共和县| 靖边县| 龙游县| 广安市| 德安县| 博客|