65.9K
CodeProject 正在变化。 阅读更多。
Home

BPEL 调用 WebService 的示例

starIconstarIconstarIconstarIcon
emptyStarIcon
starIcon

4.67/5 (3投票s)

2009年2月27日

CPOL

2分钟阅读

viewsIcon

91108

downloadIcon

1396

以下示例展示了如何在 BPEL 中调用现有的/外部的 WebService。 此示例使用 Eclipse、Eclipse BPEL 设计器插件和 Apache ODE。

引言

以下示例展示了如何在 BPEL 中调用现有的/外部的 WebService。 此示例使用 Eclipse、Eclipse BPEL 设计器插件和 Apache ODE。

背景

Using the Code

本文包含两个部分

  • Part A:准备一个 Web Service
  • Part B:在 BPEL 中调用此 Web Service

Part A:准备 Web Service

  1. 创建一个名为“DoSomethingWebService”的 Web Service,它只有一个类“DoSomething”(位于命名空间“ws.example”下),并且只有一个方法“doSomething”。 您可以使用自下而上的方法来构建此 Web Service。 请参阅此链接
    package ws.example;
    public class DoSomething {
                public String doSomething(String myinput)
                {
                            System.out.println("doSomething is called");
                            return "doSomething is called ";
                }
    }
  2. 检查生成的 WSDL 文件,服务名称为“DoSomethingService”,端口为“DoSomething”,绑定地址为 https://:8080/DoSomethingWebService/services/DoSomething

    图 1:“DoSomethingService”Web Service
  3. 将服务导出为 war 文件,并将其部署到 $TomcatHome/webapps 下。 如果需要,也可以导出并部署测试客户端,这对于测试很有帮助。 请参阅此链接

Part B:在 BPEL 中调用此 Web Service

  1. 准备 ODE 和 BPEL 插件,并创建一个名为“InvokeWebServiceProj”的 BPEL 项目,以及一个位于命名空间“http://MyTest.com/Test”下的同步 BPEL 流程“Caller”。 请参阅此链接
  2. DoSomething.wsdl 导入到项目中,并创建一个名为“DSLink”的伙伴链接,类型为“DSLinkType”,伙伴角色为“DSProvider”。 请参阅此链接

    图 2:“DSLinkType”
  3. 在“Caller”流程中添加 AssignAssign1 和 Invoke 块

    图 3:“Caller”BPEL 流程
  4. 编辑 Invoke 块以调用“doSomething”。

    图 4:“Invoke”块
  5. 从“Assign”块初始化“DSLinkRequest”,选择 From->Fixed Value 和 To->DSLinkRequest>parameters。 固定值如下所示:
    <xsd:doSomething xmlns:xsd="http://example.ws">
                                <xsd:myinput/>
                            </xsd:doSomething>

    图 5:初始化“DSLinkRequest”
  6. 设置“doSomething”方法输入值。 选择 From->Variable->input->payload->input 和 To->Variable->DSLinkRequest->parameters->myinput。

    图 6:设置“DSLinkRequest”的“myinput”
  7. 从“Assign1”块初始化“output”。 选择 From->Fixed Value 和 To->output>payload。 固定值如下所示:
    <tns:CallerResponse xmlns:tns="http://MyTest.com/Test">
                                <tns:result/>
                            </tns:CallerResponse>

    图 7:初始化“output”
  8. 设置“Caller”流程的输出值。 选择 From->Variable->DSLinkResponse->parameters->dosomethingReturn 和 To->Variable->output->payload->result。

    图 8:设置“output”的“result”
  9. 编辑生成的 Caller.wsdl,以便将“CallerService”的端口“CallerPort”绑定到“Caller”流程,地址为“https://:8080/ode/processes/Caller”,使用 SOAP。

    图 9:“CallerService”Web Service
  10. 创建 deploy.xml
    <?xml version="1.0" encoding="UTF-8"?>
    <deploy xmlns="http://ode.fivesight.com/schemas/2006/06/27/dd"
        xmlns:pns="http://MyTest.com/Test"
        xmlns:wns="http://example.ws">
    
      <process name="pns:Caller">
        <active>true</active>
        <provide partnerLink="client">
          <service name="pns:CallerService" port="CallerPort"/>
        </provide>
        <!-- If there is a BPEL process which is also deployed under the same project-->
        <!--<provide partnerLink="DSLink">
          <service name="wns:DoSomethingService" port="DoSomething"/>
        </provide>-->
        <!-- DoSomethingService is an existing/external Web Service -->
         <invoke partnerLink="DSLink">
              <service name="wns:DoSomethingService" port="DoSomething"/>
         </invoke>
         <cleanup on="always" />
      </process>
      </deploy>
  11. 测试。

    图 10:测试结果

    这是 BPEL 项目的文件列表(Caller.bpelexCaller.wsdl CallerArtifacts.wsdl 是生成的)。

    图 11:文件列表

历史

  • 2009年2月27日:初始发布
© . All rights reserved.