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");
}
}