??xml version="1.0" encoding="utf-8" standalone="yes"?>久久国产综合,亚洲精品aⅴ中文字幕乱码,四虎国产精品永远http://www.aygfsteel.com/wuxufeng8080/category/12717.htmlzh-cnSat, 03 Mar 2007 05:00:07 GMTSat, 03 Mar 2007 05:00:07 GMT60Java6 WebServices Q二Q客L (ZT)http://www.aygfsteel.com/wuxufeng8080/articles/89492.html风h?/dc:creator>风h?/author>Fri, 22 Dec 2006 04:54:00 GMThttp://www.aygfsteel.com/wuxufeng8080/articles/89492.html?a _fcksavedurl="http://blog.csdn.net/vip01/archive/2006/12/20/1450269.aspx">Java6 WebServices Q一Q服务端q篇文章中和大家分n了Java6 WebServices 服务端的写法Q光有服务端q不行,q要有客L才行啊。看了一些网友的相关文章Q都只给Z服务端的写法Q没有说客户端怎么说。经q一番研IӞl于搞定了客LQ今天偶和大家分n下?br />首先启动Java6 WebServices Q一Q服务端一文中写好的服务端?br />新徏个项目。命令行到src目录执行Q?br />wsimport -keep  http://localhost:8080/HelloService?wsdl
会自动生成一些代码?br />

package org.hermit.study.jdk.client;

import javax.jws.WebMethod;
import javax.jws.WebParam;
import javax.jws.WebResult;
import javax.jws.WebService;
import javax.jws.soap.SOAPBinding;


/**
 * This class was generated by the JAXWS SI.
 * JAX-WS RI 2.0_02-b08-fcs
 * Generated source version: 2.0
 * 
 
*/
@WebService(name 
= "Hello", targetNamespace = "http://jdk.study.hermit.org/client")
@SOAPBinding(style 
= SOAPBinding.Style.RPC)
public interface Hello {


    
/**
     * 
     * 
@param arg0
     * 
@return
     *     returns java.lang.String
     
*/
    @WebMethod
    @WebResult(partName 
= "return")
    
public String sayHello(
        @WebParam(name 
= "arg0", partName = "arg0")
        String arg0);

}

package org.hermit.study.jdk.client;

import java.net.MalformedURLException;
import java.net.URL;
import javax.xml.namespace.QName;
import javax.xml.ws.Service;
import javax.xml.ws.WebEndpoint;
import javax.xml.ws.WebServiceClient;


/**
 * This class was generated by the JAXWS SI.
 * JAX-WS RI 2.0_02-b08-fcs
 * Generated source version: 2.0
 * 
 
*/
@WebServiceClient(name 
= "HelloService", targetNamespace = "http://jdk.study.hermit.org/client", wsdlLocation = "http://localhost:8080/HelloService?wsdl")
public class HelloService
    
extends Service
{

    
private final static URL HELLOSERVICE_WSDL_LOCATION;

    
static {
        URL url 
= null;
        
try {
            url 
= new URL("http://localhost:8080/HelloService?wsdl");
        } 
catch (MalformedURLException e) {
            e.printStackTrace();
        }
        HELLOSERVICE_WSDL_LOCATION 
= url;
    }

    
public HelloService(URL wsdlLocation, QName serviceName) {
        
super(wsdlLocation, serviceName);
    }

    
public HelloService() {
        
super(HELLOSERVICE_WSDL_LOCATION, new QName("http://jdk.study.hermit.org/client""HelloService"));
    }

    
/**
     * 
     * 
@return
     *     returns Hello
     
*/
    @WebEndpoint(name 
= "HelloPort")
    
public Hello getHelloPort() {
        
return (Hello)super.getPort(new QName("http://jdk.study.hermit.org/client""HelloPort"), Hello.class);
    }

}

下面我们再写个测试,看看能不能用Q?br />
package org.hermit.study.jdk.client.test;

import org.hermit.study.jdk.client.Hello;
import org.hermit.study.jdk.client.HelloService;


public class TestClient {
    
public static void main(String[] args) {
        HelloService service 
= new HelloService();
        Hello _hello 
= service.getHelloPort();
        System.out.println(_hello.sayHello(
"hermit"));
    }
}
执行?br />控制台输出:
hello:hermit

okQ搞定?br />java6搞定web servicep么简单。。。。。。。。。。。。。。。。。。。。。。。。。?br />
xfire危险了。。。。。。。。。。。。。。。。。。。。。。。?/div>

]]>
Java6 WebServices Q一Q服务端 (ZT)http://www.aygfsteel.com/wuxufeng8080/articles/89491.html风h?/dc:creator>风h?/author>Fri, 22 Dec 2006 04:53:00 GMThttp://www.aygfsteel.com/wuxufeng8080/articles/89491.html下面开始写个最单的WebServicesQ?br />
package org.hermit.study.jdk;

import javax.jws.WebMethod;
import javax.jws.WebService;
import javax.jws.soap.SOAPBinding;

@WebService(targetNamespace 
= "http://jdk.study.hermit.org/client")
@SOAPBinding(style 
= SOAPBinding.Style.RPC)
public class Hello {
    @WebMethod
    
public String sayHello(String name) {
        
return "hello:" + name;
    }
}
怎么Lz吧Q很多朋友的写法q要在命令行中执行?span style="FONT-FAMILY: 'Courier New',Courier,monospace">wsgen –cp . <path>?br />用偶q种Ҏ写的service可以省去上面q步?br />
targetNamespace = "http://jdk.study.hermit.org/client"q句是指定客L获取服务端服务后存放的类路径。注意是反着的,http: //jdk.study.hermit.org/client在客L生成的类会放在org.hermit.study.jdk.client包下?br />下面是发布服务:
package org.hermit.study.jdk;

import javax.xml.ws.Endpoint;

public class StartService {
    
public static void main(String[] args) {
        Endpoint.publish(
"http://localhost:8080/HelloService"new Hello());
    }

}
呵呵Q更z。一句话而已?br />http://localhost:8080/HelloService是指发布的地址

q行
StartService Q开发浏览器输入Qhttp://localhost:8080/HelloService?wsdl



如果能看C下内容,可?br />
 <?xml version="1.0" encoding="UTF-8" ?> 
<definitions xmlns="http://schemas.xmlsoap.org/wsdl/" xmlns:tns="http://jdk.study.hermit.org/client" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" targetNamespace="http://jdk.study.hermit.org/client" name="HelloService">
  
<types /> 
<message name="sayHello">
  
<part name="arg0" type="xsd:string" /> 
  
</message>
<message name="sayHelloResponse">
  
<part name="return" type="xsd:string" /> 
  
</message>
<portType name="Hello">
<operation name="sayHello" parameterOrder="arg0">
  
<input message="tns:sayHello" /> 
  
<output message="tns:sayHelloResponse" /> 
  
</operation>
  
</portType>
<binding name="HelloPortBinding" type="tns:Hello">
  
<soap:binding style="rpc" transport="http://schemas.xmlsoap.org/soap/http" /> 
<operation name="sayHello">
  
<soap:operation soapAction="" /> 
<input>
  
<soap:body use="literal" namespace="http://jdk.study.hermit.org/client" /> 
  
</input>
<output>
  
<soap:body use="literal" namespace="http://jdk.study.hermit.org/client" /> 
  
</output>
  
</operation>
  
</binding>
<service name="HelloService">
<port name="HelloPort" binding="tns:HelloPortBinding">
  
<soap:address location="http://localhost:8080/HelloService" /> 
  
</port>
  
</service>
  
</definitions>


]]>
通过 Axis2 开?Web 服务Q第 1 部分: 通过 Axis2 q行旉|和使用?Web 服务http://www.aygfsteel.com/wuxufeng8080/articles/56378.html风h?/dc:creator>风h?/author>Mon, 03 Jul 2006 09:01:00 GMThttp://www.aygfsteel.com/wuxufeng8080/articles/56378.html 引言

Axis2 是下一?Apache Axis。Axis2 虽然?Axis 1.x 处理E序模型提供支持Q但它具有更强的灉|性ƈ可扩展到新的体系l构。Axis2 Z新的体系l构q行了全新编写,而且没有采用 Axis 1.x 的常用代码。支持开?Axis2 的动力是探寻模块化更强、灵zL更高和更有效的体系l构Q这U体pȝ构可以很Ҏ地插入到其他相关 Web 服务标准和协议(?WS-Security、WS-ReliableMessaging {)的实C?/p>

Axis2 的特性包括:

  • 采用名ؓ AXIOMQ?b>AXIs Object ModelQAxis 对象模型Q的新核?XML 处理模型
  • 支持 In-Only ?In-Out 消息交换模式 (MEP)
  • d和非d客户?APIQ应用程序编E接口)
  • 支持内置?Web 服务d (WS-Addressing)
  • 支持 XMLBeans 数据l定
  • 新部|模?
  • 支持文本传输协?(HTTP)、简单邮件传输协?(SMTP) 和传输控制协?(TCP) {传输协?

本系列文章以 Axis2 0.92 版本为基。您可以?Apache |站获得 Axis2 的最新版本?/p>



回页?/font>


Axis 体系l构概述


?1. Axis2 体系l构
Axis2 体系l构

Axis2 体系l构逻辑与状态分;q允许在q行U程中执行逻辑。服务和调用的静态状态和动态状态分别存储在 Description ?Context cM。Axis2 体系l构是?7 个独立模块实现的?/p>

  1. 信息模型Q?/b>此模块管?SOAP 引擎的状态。该模型定义一l用于存攄态的c,而引擎管理这些信息对象的生命周期。信息模型包含两U用于存攄态的cR?code>Description cd放本质上是静态的且存在于 Axis 引擎实例的整个生命周期中的数据(如传输、服务和操作的配|)?code>Context cd放调用上下文中有效的服务和操作的动态信息,例如当前h和响?SOAP 消息、From 地址、To 地址和其他元素?
  2. XML 处理模型Q?/b>Axis2 引入了一个名?AXIOM 的新模型Q用于处?SOAP 消息。AXIOM 使用 StAX (Streaming API for XML) 来解?XML。StAX 是一个标准的式 Pull 解析?Java?API。AXIOM 非常_yQ不会减?XML 信息集的构徏速度——换句话_对象只有在绝对必要时才会创徏。M而言QAXIOM ?Axis2 所占用的内存要于 Axis 1 所占用的内存?
  3. SOAP 处理模型Q?/b>Axis2 体系l构定义了两个管道(或流Q,分别UCؓ InPipe (InFlow) ?OutPipe (OutFlow)Q用于处理服务器端的h消息和响应消息。在客户端,q两个管道是反向的——换句话_SOAP h消息经 OutPipeQ而响应消息流l?InPipe。管道或包含一pd分ؓ阶段的处理程序。阶D|照预先定义的序执行Q如上面?a >?1 所C。除预先定义的阶D和处理E序集外Q用戯可以在操作别、服务别或全局U别配置用户阶段和相兛_理程序。处理程序充?SOAP 消息的拦截器Q可以处?SOAP 消息?Header ?Body。InPipe 是通过以下阶段q行配置的:
    • TransportIn
    • PreDispatch
    • Dispatch
    • PostDispatch
    • PolicyDetermination
    • User phases
    • Message validation
    我们在本系列文章的W?2 部分中详l介l上q各阶段。请求消息在通过 Inpipe 中配|的所有阶D后Q到?MessageReceiverQ然后由 MessageReceiver 调用实际服务实现。服务器?OutPipe 包含以下阶段Q?
    • Message initialization
    • Policy determination
    • User phases
    • MessageOut
    用户配置的阶D位于这两个道的用户阶D?User phases) 部分。如果在执行q些道的过E中发生错误Q则q些错误通过 InFaultPipe ?OutFaultPipe 道。收?Fault 消息后,在客L调用 InFaultPipeQ如果某个调用导致将错误发送到客户端,则在服务器端调用 OutFaultPipe。用户可以将处理E序d到预先定义的阶段Qƈ且按照这些处理程序运行的序q行配置?
  4. 部v模块Q?/b>此模块配|?Axis 引擎q|服务和模块?i>axis2.xmlQ在 webapps/axis2/WEB-INF 中)包含 Axis2 引擎的全局配置Q包括:
    • 全局模块 (Global modules)
    • 全局接收?(Global receivers)
    • 传输 (Transports)
    • 用户阶段定义 (User phase definitions)
    每个服务的配|都包含在服务存档的 services.xml 文g中。本文稍后将详细讨论此文件?
  5. WSDL 和代码生成:此模块从 WSDL 文g中生成客L存根和服务器框架代码。Axis2 代码生成器发出采用正?XML 样式表的 XML 文gQ以用所需语言生成代码?
  6. 客户?APIQ?/b>Axis2 客户?API 调用遵@ WSDL 2.0 定义?In-Only ?In-Out 消息模式的操作。客L API 支持 In-Out 操作的阻塞和非阻塞调用?
  7. 传输Q?/b>此模块包含与传输层交互的处理E序。传输处理程序有两种cdQTransportListener ?TransportSender。TransportListener 从传输层接收 SOAP 消息Q然后将其传送到 InPipe q行处理。TransportSender 发送通过指定传输?OutPipe 接收到的 SOAP 消息。Axis2 提供 HTTP、SMTP ?TCP 的处理程序。对?HTTP 传输Q服务器端上?AxisServlet 和客L上的一个简单的独立 HTTP 服务器(?Axis2 提供Q充?TransportReceiver?




回页?/font>


部v Axis2

部v Axis2 与部|?Axis 1 一L单。首先在 Axis2 二进制代码分发包?webapps 目录下查?Axis2 Web 应用E序 axis2.war。在 servlet 容器中部|此 war 文g。在 Tomcat 中,如果已在服务器配|中?unpackWARs 讄?TrueQ则只需?axis2.war 复制?$TOMCAT_HOME/webapps 目录卛_部v Axis2。请立即启动 Tomcat q访?http://localhost:<port>/axis2。将昄 Axis2 Ƣ迎,单击此页上的 Validate 链接。您应到?Axis2 Happiness pageQ不会出CQ何错误?/p>



回页?/font>


开?StockQuoteService

下面介绍如何使用 In-Only subscribe() ?In-Out getQuote() q两个操作来开?StockQuoteService。subscribe() 操作预订指定代L每小时报P?getQuote() 获得指定代L当前报h?/p>

下面?a >清单 1 ?StockQuoteService 的实现示例:


清单 1. StockQuoteService 实现
				
package stock;
import org.apache.axis2.om.OMAbstractFactory;
import org.apache.axis2.om.OMElement;
import org.apache.axis2.om.OMFactory;
import org.apache.axis2.om.OMNamespace;
		
public class StockQuoteService {
		 
  public void subscribe(OMElement in){
    String symbol = in.getText();
    System.out.println("Subscription request for symbol ="+symbol);
    // put the actual subscribe code here...    
  }
		  
		  
  public OMElement getQuote(OMElement in){
		  
    // Get the symbol from request message
    String symbol = in.getText();
		    
    int quote = 0;
    if(symbol.equals("IBM")){
      quote = 100;
    }
    // Put more quotes here ...
		    
    // Create response
    OMFactory fac = OMAbstractFactory.getOMFactory();
    OMNamespace omNs = fac.createOMNamespace(
      "http://www.developerworks.com/example", "example");
    OMElement resp = fac.createOMElement("getQuoteResponse", omNs);
    resp.setText(String.valueOf(quote));
    return resp;      
  }
}

Ҏ法签名感到很疑惑Q我们将讨论上述Ҏ中的 OMElement?/p>



回页?/font>


部v服务

部v描述W?/b>

?Axis2 中,服务部v信息包含?services.xml 文gQ在 0.92 以前的版本中Q此文g名ؓ service.xmlQ中。对于上q?StockQuoteServiceQ服务部|描q符与下面的清单 2 cM?/p>
清单 2. Services.xml
				
<service name="StockQuoteService">
  <parameter name="ServiceClass" locked="xsd:false">
    stock.StockQuoteService
  </parameter>
		
  <operation name="getQuote">
    <messageReceiver 
      class="org.apache.axis2.receivers.RawXMLINOutMessageReceiver"/>
  </operation>
		
  <operation name="subscribe">
    <messageReceiver 
      class="org.apache.axis2.receivers.RawXMLINOnlyMessageReceiver"/>
  </operation>
</service>

服务?name 属性定义服务的名称。Axis2 使用服务的名U创建服务的端点地址Q例?http://localhost:<port>/axis2/services/<nameofservice>。因此,对于 StockQuoteServiceQ服务端点ؓ http://localhost:<port>/axis2/services/StockQuoteService?code>ServiceClass 参数指定服务实现cR?/p>

每个 <operation> 元素定义服务中一个操作的配置?lt;operation> ?name 属性应讄为服务实现类中方法的名称?code>messageReceiver 元素定义用于处理此操作的消息接收器。Axis2 针对 In-Only ?In-Out 操作提供了两个无数据l定的内|?MessageReceiversQ?code>org.apache.axis2.receivers.RawXMLINOnlyMessageReceiver 用于 In-Only 操作Q?org.apache.axis2.receivers.RawXMLINOutMessageReceiver 用于 In-Out 操作。如果没有指?messageReceiverQ则 Axis2 尝试?org.apache.axis2.receivers.RawXMLINOutMessageReceiver 作ؓ~省?messageReceiver。上q?RAWXML 消息接收器将传入 SOAP 消息?<Body> 的内容作?OMElementQOMElement ?XML 元素?AXIOM ~写Q传递给服务实现。此操作应作?OMElement q回 SOAP 响应?<Body> 元素包含?XML 内容。这便解释了Z subscribe() ?getQuote() 操作采用和返?OMElement?/p>

services.xml q可以包含分?servicegroup 的多个服务?/p>

打包

Axis 2 服务是作?Axis Archive (.aar) 打包的。这是一?JAR 文gQ?jar ?zip 实用E序创徏Q,在存档的 META-INF 目录中打包了 services.xml 文g。StockQuoteService 在打包成 StockQuoteService.aar 时将h以下l构Q?

./stock/StockQuoteService.class
./META-INF/services.xml

预先打包?StockQuoteService 存档可以在本文的下蝲部分中找到?/p>

部v

?Axis2 中部|服务相当简单,只需?.aar 文g复制?servlet 容器?axis2 Web 应用E序中的 axis2/WEB-INF/services 目录下即可。对?TomcatQ此位置?$TOMCAT_HOME/webapps/axis2/WEB-INF/services?

另一U部|服务的好方法是使用 Axis2 理控制C?Upload Service 工具。请转到 http://localhost:<port>/axis2Q然后选择 Administration 链接。输入用户名和密?admin/axis2Q然后登录。(您可以在 axis2.xml 中配|用户名/密码?在工具部分选择 Upload Service 链接Q再选择 .aar 文gQ然后单?Upload。就是这L单!如果上传成功Q系l将昄一条绿色成功消息。服务即被部|Ԍ而且可随时调用。如果要在远E?Axis2 服务器上部v服务Q则此功能非常方ѝ?/p>



回页?/font>


通过 Axis2 使用 Web 服务

Web 服务调用的特性由 MEP、传输协议以及客L API 的同步和/或异步行为决定。Axis2 当前支持 WSDL 2.0 定义?In-Only ?In-Out MEP。Axis2 客户?API 支持服务的同步和异步调用。在调用 In-Out 操作Ӟ?API U别和传输别提供异步行为。API U别异步是通过回滚获得的,它用一个传输连接来同时传输h和响应(例如Q通过一?HTTP q接传输h和响应)。在传输U别异步中,使用不同的传输连接分别发送请求和接收响应Q例如?SMTP q行传输时即如此?/p>

下面是?Axis2 客户?API 调用 In-Only ?In-Out 操作的详l信息?/p>

调用 In-Only 操作

org.apache.axis2.clientapi.MessageSender cȝ于调?In-Only 操作Q如下面?a >清单 3 所C)Q?In-Only 操作调用 StockQuoteService ?subscribe() 操作?/p>
清单 3. 调用 In-Only 操作
				
try{
  EndpointReference targetEPR = new EndpointReference(
      "http://localhost:8080/axis2/services/StockQuoteService");
          
  // Make the request message
  OMFactory fac = OMAbstractFactory.getOMFactory();
  OMNamespace omNs = fac.createOMNamespace(
      "http://www.developerworks.com/example", "example");
  OMElement payload = fac.createOMElement("subscribe", omNs);
  payload.setText("IBM"); 
          
  // Send the request
  MessageSender msgSender = new MessageSender();
  msgSender.setTo(targetEPR);
  msgSender.setSenderTransport(Constants.TRANSPORT_HTTP);
  msgSender.send("subscribe", payload);         
  }catch (AxisFault axisFault) {
      axisFault.printStackTrace();
  }

MessageSender.send() 发送请求消息ƈ其立即q回。要使用的传输由 MessageSender.setSenderTransport() 指定。此CZ通过 HTTP 发送消息?/p>

调用 In-Out 操作

使用 org.apache.axis2.clientapi.Call cd以方便地调用 In-Out 操作。调?In-Out 操作Ӟ?Call cL持下?4 U模式:

  1. d单传输模?/b>Q这是调?In-Out Web 服务操作最单的方式。在操作完成和接收到响应或错误之前,服务调用被阻塞。它使用一个传输连接同时发送和接收响应Q如下面?a >清单 4 所C?/p>

    清单 4. d单传输模?/b>
    						
    try {
                     
      EndpointReference targetEPR = new EndpointReference(
          "http://localhost:8080/axis2/services/StockQuoteService");
                   
      // Create request message
      OMFactory fac = OMAbstractFactory.getOMFactory();
      OMNamespace omNs = fac.createOMNamespace(
          "http://www.developerworks.com/example", "example");
        OMElement payload = fac.createOMElement("getQuote",omNs);
      payload.setText("IBM");
    
      // Create the call
      Call call = new Call();
      call.setTo(targetEPR);
    			
      call.setTransportInfo(Constants.TRANSPORT_HTTP,
        Constants.TRANSPORT_HTTP, false);
      // Invoke blocking
      OMElement result = call.invokeBlocking("getQuote", payload);
                   
      System.out.println("Quote ="+result.getText());
    }catch (AxisFault axisFault) {
        axisFault.printStackTrace();
    }
    

    代码的第一部分使用 AXIOM 创徏h消息?code>Call.setTransportInfo() 讄用于发送请求和获得响应的传输?code>Call.setTransportInfo() 操作?Boolean 参数指出是否要用不同的传输q接来分别发送请求和接收响应。在本例中,要求用一?HTTP q接发送请求和接收响应?/p>

  2. 非阻塞单传输模式Q在此调用模式中Q只使用下面的一个传输连接获得非d调用。如果在一个客L应用E序中要完成多个 Web 服务调用Q而且不希望每ơ调用都d客户端,则需要此c行为。此Ӟ如果响应可用Q则调用立即q回且客L得以回滚Q如下面?a >清单 5 所C?/p>

    清单 5. 非阻塞单传输模式
    						
    try {
      EndpointReference targetEPR = new EndpointReference(
          "http://localhost:8080/axis2/services/StockQuoteService");
                
      //Create the request
      OMFactory fac = OMAbstractFactory.getOMFactory();
      OMNamespace omNs = fac.createOMNamespace(
          "http://www.developerworks.com/example", "example");
      OMElement payload = fac.createOMElement("getQuote", omNs);
      payload.setText("IBM");
          
                
        // Create the call
        Call call = new Call();
        call.setTo(targetEPR);
                
        // Set the transport info.
        call.setTransportInfo(org.apache.axis2.Constants.TRANSPORT_HTTP,
          org.apache.axis2.Constants.TRANSPORT_HTTP, false);
                
      // Callback to handle the response
                
        Callback callback = new Callback() {
          
          public void onComplete(AsyncResult result) {
            System.out.println("Quote = "
              + result.getResponseEnvelope().getBody().getFirstElement()
                .getText());
          }
          
          public void reportError(Exception e) {
            e.printStackTrace();
          }
        };
                
                
      // Invoke non blocking
                
        call.invokeNonBlocking("getQuote", payload, callback);            
                
      //Wait till the callback receives the response.
                
        while (!callback.isComplete()) {
          Thread.sleep(1000);
        }
                
                
      call.close();
    } catch (AxisFault axisFault) {
      axisFault.printStackTrace();
    } catch (Exception ex) {
      ex.printStackTrace();
    }
    

    Call.invokeNonBlocking() Ҏ立即q回而不d?code>Call.invokeNonBlocking() 采用 org.apache.axis2.clientapi.CallBack 的对象,如果响应来自服务Q则触发此对象?code>CallBack 有两个抽象方?onComplete(AsynchResult) ?reportError(Exception)Q需要由具体?CallBack cd现这些方法。在服务调用正常完成后,Axis2 引擎调用 onComplete() Ҏ。在从服务器获得错误消息后,调用 Callback ?reportError() Ҏ?code>Callback.isComplete() 指出操作调用是否完成?/p>

    因ؓ上面两个Ҏ使用一个传输连接来发送和接收消息Q所以这些方法不适合长时间运行的事务。原因是在响应可用之前,传输q接可能会超时。要解决此问题,可用两个不同的q接来分别发送请求和接收响应。但因ؓ使用了其他传输连接来获得响应Q因此需要将h和响应关联v来。Axis2 支持 WS-AddressingQ后者通过使用 <wsa:MessageID> ?<wsa:RelatesTo> Header 可解x问题。因此,如果使用两个传输Q则支持Ҏ块寻址Q如下面两个模式所C?/p>

  3. d双传输模?/b>Q此模式在以下情况下非常有用Q服务操作在本质上是 In-OutQ但使用的传输是单向的(?SMTPQ或服务执行需要很长时间且 HTTP q接时。请参见下面?a >清单 6?/p>

    清单 6. d双传输模?/b>
    						
    try{
      EndpointReference targetEPR = new EndpointReference(
          "http://localhost:8080/axis2/services/StockQuoteService");
                    
      OMFactory fac = OMAbstractFactory.getOMFactory();
      OMNamespace omNs = fac.createOMNamespace(
          "http://www.developerworks.com/example", "example");
      OMElement payload = fac.createOMElement("getQuote",omNs);
      payload.setText("IBM");
            
      Call call = new Call();
        call.setTo(targetEPR);
    
        call.setTransportInfo(
          Constants.TRANSPORT_HTTP, Constants.TRANSPORT_HTTP, true);
    
        //Blocking Invocation
        OMElement result = call.invokeBlocking("getQuote", payload);
      System.out.println("Quote = "+result.getText());
    	
    }catch (AxisFault axisFault) {
        axisFault.printStackTrace();
    }catch (Exception ex) {
        ex.printStackTrace();
    }
    

  4. 非阻塞双传输模式Q就 API U别和传输别的非阻塞而言Q此模式提供了最大的灉|性,如下面的清单 7 所C?/p>

    清单 7. 非阻塞双传输模式
    						
    try {
           
      EndpointReference targetEPR = new EndpointReference(
          "http://localhost:8080/axis2/services/StockQuoteService");
      OMFactory fac = OMAbstractFactory.getOMFactory();
      OMNamespace omNs = fac.createOMNamespace(
          "http://www.developerworks.com/example", "example");
      OMElement payload = fac.createOMElement("getQuote",omNs);
      payload.setText("IBM");
            
               
        Call call = new Call();
        call.setTo(targetEPR);
    
        call.setTransportInfo(
          Constants.TRANSPORT_HTTP, Constants.TRANSPORT_HTTP, true);
      // Callback to handle the response
               
        Callback callback = new Callback() {
        public void onComplete(AsyncResult result) {
          System.out.println("Quote = "
              + result.getResponseEnvelope().getBody().getFirstElement()
            .getText());
          }
    
        public void reportError(Exception e) {
            e.printStackTrace();
          }
        };
                
    
      // Non-Blocking Invocation
              
        call.invokeNonBlocking("getQuote", payload, callback);
      // Wait till the callback receives the response.
              
        while (!callback.isComplete()) {
          Thread.sleep(1000);
        }
        call.close();          
    }catch (AxisFault axisFault) {
          axisFault.printStackTrace();
    }catch (Exception ex) {
          ex.printStackTrace();
    }
    





回页?/font>


ȝ

在这一׃部分l成的系列的W?1 部分中,您了解了 Axis2 体系l构以及如何使用不同的调用模式来部v和用一个简单的 Web 服务。在本系列的W?2 部分中,您将详细了解该体pȝ构,以及如何通过d处理E序?Axis2 消息接收器来自定?Axis2。您q将了解如何使用 Axis2 提供?XMLBeans 数据l定支持?/p>


]]>
վ֩ģ壺 | ɽ| ֶ| | | | | | | | | | | | | | ֶ| | ˳| ʼ| Ͻ| Ϫ| ˹| | | | ˮ| | ȫ| ʻ| | | Ϳ| Ͱ| | ƽ| | | | | ɳ|