欢迎访问昆山宝鼎软件有限公司网站! 设为首页 | 网站地图 | XML | RSS订阅 | 宝鼎邮箱 | 宝鼎售后问题提交 | 后台管理


新闻资讯

MENU

软件开发知识
原文出处: 袁鸣凯

一、SOAPIn Axis2

在前两天的教程中,我们进修到了用Axis2如何举办巨大数据、简朴数据举办传输。

正如我在前一天教程中所说,在web service的世界里,一切都是基于SOAP的,昆山软件公司,因此在本日我们将进修Axis2中的SOAP特性。

本日的课程将用3个例子来完成即:

  1. 客户端与处事端利用SOAP举办通讯
  2. 处事端将Exception以SOAPFault的形式抛给客户端
  3. 利用SWA(Soap With Attachment)来举办附件传送

二、客户端与处事端利用SOAP举办通讯

来看下面这个Web Service:

即客户端把需  <a href=昆山软件定制开拓 要上传的文件" src="/uploads/allimg/c180215/151V3Z56041F-14I0.jpg" />

 

下面是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);

                   soapResponse.build();

 

                   return soapResponse;

         }

 

}

即客户端把需  <a href=昆山软件定制开拓 要上传的文件" style="font-weight: normal;" src="/uploads/allimg/c180215/151V3Z5A2930-2Y26.jpg" />来看它的service.xml的描写

<service name="SoapService">

         <description>

                   This is the service for revoking certificate.

         </description>

         <parameter name="ServiceClass" locked="false">

                   org.sky.axis2.soap.SoapService

         </parameter>

         <operation name="request">

                   <messageReceiver

                            class="org.apache.axis2.receivers.RawXMLINOutMessageReceiver" />

                   <actionMapping>urn:request</actionMapping>

         </operation>

</service>

该Web Service接管一个Soap请求,该请求为如下名目:

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:soap="http://soap.axis2.sky.org">

   <soapenv:Header/>

   <soapenv:Body>

      <soap:request>

           <soap:request>?</soap:request>

      </soap:request>

   </soapenv:Body>

</soapenv:Envelope>

个中<soap:request></soap:request>中间的内容,应该如下所示:

<Request xmlns="http://10.225.104.122">

    <Issuer>1234567890</Issuer>

    <Serial>11111111</Serial>

    <RevokeDate>2007-01-01</RevokeDate>

</ Response >

我们假设它是一个购置图书的定单,处事端收到这个请求后会返回一个定单信息给挪用它的客户端,处事端将返回如下内容(此处不做任何业务处理惩罚,只是很简朴的传值回客户端)。

<SoapResponse xmlns="http://soap.axis2.sky.org">

    <Issuer>issuer: Wrox</Issuer>

    <Serial>serial: 1111111111ISBN</Serial>

    <RevokeDate>RevocationDate: 2012-07-29</RevokeDate>

</SoapResponse>

为生成上述这个SoapResponse我们在Service端的焦点代码如上面加粗部门的代码所示,由其留意这个“soapResponse.build();”。

下面我们来看这个客户端是怎么写的,昆山软件开发,我们这边用的长短阻塞式客户端