一個調用WebService的BPEL程式轉載http://www.codeproject.com/KB/webservices/BPELInvokeWebService.aspx?fid=15366

來源:互聯網
上載者:User
文章目錄
  • 第一部分:
下面的展示了用BPEL調用一個外部的或者存在的web service的例子。使用Eclipse-BPEL和Apache ODE

      本文章總共分為兩部分:一部分開發一個Web Service,一部分實現在BPEL中調用

第一部分:

      準備好一個web service

1、首先建立一個web service,名字叫“DoSomethingWebService”。它僅有一個類“DoSomething”,包名為“ws.example”,在這個類中定義一個方法“doSomething”。你可以使用自底向上建立這個類,具體參見:http://www.eclipse.org/webtools/jst/components/ws/1.5/tutorials/BottomUpWebService/BottomUpWebService.html
在做這個web service時一定要按照步驟一步一步來,看清楚圖形表示。

 

DoSomething代碼為:

package ws.example;</p><p>public class DoSomething<br />{<br />public String doSomething(String myinput)<br />{<br />System.out.println("doSomething is called");<br />return "doSomething is called";<br />}<br />}<br />

 

2、檢查所產生的WSDL檔案,service名字為“DoSomethingService”,Port為“DoSomething”,綁定地址為“http://localhost:8080/DoSomethingWebService/services/DoSomething”

:

3、匯出這個服務,以war的形式,並把它放到tomcat的webapps下面,用戶端也可以匯出,方便測試。

匯出直接選中wsdl檔案匯出即可。

 

第二部分:

        1、準備好Apache ode和Eclipse BPEL建立BPEL工程“InvokeWebServiceProj”,然後建立同步 (synchronous )BPEL進程“Caller”,namespace為“http://MyTest.com/Test”。

        2、匯入WSDL檔案即"DoSomething.wsdl",這時候要將先前產生的wsdl檔案複製到當前項目中。建立立一個partnerLink,名字叫做“DSLink”。類型(Type)為“DSLinkType”,Partner Role of為“DSProvider” 。如何不知道如何建立partner link參見“http://www.eclipse.org/bpel/users/howto/wsdl.php”

注意:引入的WSDL檔案一定要是從本檔案中引入,即InvokeWebServiceProj。

 

 3、加入Assign,Assign1和invoke。:

4、編輯Invoke模組,調用doSomething。:

5、編輯Assign模組。點擊“new”,“From”選擇“Fixed Value”然後填入“

<xsd:doSomething xmlns:xsd="http://example.ws"><br /> <xsd:myinput/><br /></xsd:doSomething>

”。“to”選擇“DSLinkRequestàparameters”。這是會彈出來一個視窗選擇“yes”。

:

編輯新彈出來的那個在“From”中選擇 “From->Variable->input->payload->input”,在“to”中選擇“To->Variable->DSLinkRequest->parameters->myinput”後 ,儲存。

6、編輯Assign1代碼塊。同樣點擊“new”按鈕。在“From”中選擇“Fixed Value”,填入<tns:CallerResponse xmlns:tns="http://MyTest.com/Test"><br /> <tns:result/><br /></tns:CallerResponse>

在“To”中選擇“To->outputàpayload”;

7、在這個Assign1中再點擊“new”按鈕,“From中”選擇“From->Variable->DSLinkResponse->parameters->dosomethingReturn ”,並且To中選擇“To->Variable->output->payload->result”:

8、編輯“CallerArtifacts.wsdl”,添加服務“CallerService”,Port為“CallerPort”,Address為“http://localhost:8080/ode/processes/Caller”,綁定使用的方式為“SOAP”。:

9、建立部署檔案deploy.xml。在工程中用new->other->Apache ODE Delopyment Descriptior。然後選擇:

 

 

 10、將項目放到tomcat的ode的WebINF-process中,啟動tomcat。這時候會報錯:

 

這時候需要將Caller.bpel中的引入夥伴串連的語句import中的location=“file:/E:/eclipse/worksapce/DoSomethingWebService/WebContent/wsdl/DoSomething.wsdl”改成

location="location="DoSomething.wsdl"。同樣在CallerArtifacts.wsdl也要做相應的修改,最後啟動tomcat。

訪問:http://localhost:8080/ode/services/listServices。可以看見我們發布的服務

 

 

 

 

 

 

 

 

 

 

 

 

 

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.