一、SOAPIn Axis2
在前两天的教程中,我们学习到了用Axis2如何进行复杂数据、简单数据进行传输。
正如我在前一天教程中所说,在web service的世界里,一切都是基于SOAP的,因此在今天我们将学习Axis2中的SOAP特性。
今天的课程将用3个例子来完成即:
1)客户端与服务端使用SOAP进行通讯
2)服务端将Exception以SOAPFault的形式抛给客户端
3)使用SWA(Soap With Attachment)来进行附件传送
二、客户端与服务端使用SOAP进行通讯
来看下面这个Web Service:
下面是Service端的源码
org.sky.axis2.soap.SoapService
package org.sky.axis2.soap;import org.apache.axiom.om.OMAbstractFactory;import org.apache.axiom.om.OMElement;import org.apache.axiom.om.OMFactory;import org.apache.axiom.om.OMNamespace;import java.util.*;public class SoapService { public static OMElement requestSoap = null; public OMElement request(OMElement soapBody) { requestSoap = soapBody; Iterator it = requestSoap.getChildElements(); OMElement issuerElement = (OMElement) it.next(); OMElement serialElement = (OMElement) it.next(); OMElement revocationDateElement = (OMElement) it.next(); String issuer = issuerElement.getText(); String serial = serialElement.getText(); String revocationDate = revocationDateElement.getText(); System.out.println("issuer=====" + issuer); System.out.println("serial=====" + serial); System.out.println("revocationDate=====" + revocationDate); OMFactory soapFactory = OMAbstractFactory.getOMFactory(); OMNamespace omNs = soapFactory.createOMNamespace( "http://soap.axis2.sky.org", ""); OMElement soapResponse = soapFactory.createOMElement("SoapResponse", omNs);OMElement soapIssuer = soapFactory.createOMElement("Issuer", omNs); soapIssuer.setText("issuer: " + issuer); soapResponse.addChild(soapIssuer); OMElement soapSerial = soapFactory.createOMElement("Serial", omNs); soapSerial.setText("serial: " + serial); soapResponse.addChild(soapSerial); OMElement soapRevokeDate = soapFactory.createOMElement("RevokeDate", omNs); soapRevokeDate.setText("RevocationDate: " + revocationDate); soapResponse.addChild(soapRevokeDate); return soapResponse; }}
以上是小编为您精心准备的的内容,在的博客、问答、公众号、人物、课程等栏目也有的相关内容,欢迎继续使用右上角搜索按钮进行搜索import
axis2 webservice、axis2调用webservice、axis2开发webservice、axis2发布webservice、serviceclient axis2,以便于您获取更多的相关知识。
时间: 2024-12-05 02:20:52