使用Axis2的底層API開發Web Service

來源:互聯網
上載者:User

1.使用Axis2的底層API開發Web Service Server端

1.1建立一個WebService(取名為MyService)

在MyService中有兩個operations,如下所示。

public void ping(OMElement element){}//IN-ONLY模式。僅僅接收OMElement,並對 其處理。

public OMElement echo(OMElement element){}//IN_OUT模式。接收OMElemen,並返回 OMElement。

1.2如何寫Web Service

1)建立實現服務的類。

2)建立services.xml來解析這個Web Service。

3)將其打包成一個*.aar文檔(Axis Archive)。

4)部署Web Service。

1.2.1 建立實現服務的類

此類中提供的方法必須與Web Service(在services.xml中聲明)中的operations對應 。除非你提供了資料繫結,否則所有的方法只能接收一個參數,其類型為OMElement。

public class MyService{
  public void ping(OMElement element){...}
  public OMElement echo(OMElement element){...}
}

MyService.java

package userguide.example1;
import org.apache.axiom.om.OMElement;
import org.apache.axis2.AxisFault;
import javax.xml.stream.XMLStreamException;
public class MyService {
   public OMElement echo(OMElement element) throws XMLStreamException {
     //Praparing the OMElement so that it can be attached to another OM Tree.
     //First the OMElement should be completely build in case it is not fully built and still
     //some of the xml is in the stream.
     element.build();
     //Secondly the OMElement should be detached from the current OMTree so that it can
     // be attached some other OM Tree. Once detached the OmTree will remove its
    // connections to this OMElement.
     element.detach();
     return element;
   }
   public void ping(OMElement element) throws XMLStreamException {
     //Do some processing
   }
   public void pingF(OMElement element) throws AxisFault{
     throw new AxisFault("Fault being thrown");
   }
}

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.