Webservice基于xml的数据传输

Webservice基于xml的数据传输

xml字符串进行请求校验,然后把数据以xml形式进行返回,实现数据的传输,可以在定义xml的数据格式以及要验证的方式。

 

1,把axis2整合进入项目中

首先去官网下载aixs2, axis2中的 

 

Conf文件夹,lib中的jar包,repository下面的modules文件夹和services文件夹拷贝到项目中的WEB-INF下面,然后打开webapp下面的WEB-INF/web.xml

servlet的配置拷贝到项目中的web.xml

<servlet>

<servlet-name>AxisServlet</servlet-name>

<servlet-class>org.apache.axis2.transport.http.AxisServlet</servlet-class>

<load-on-startup>1</load-on-startup>

</servlet>

<servlet>

<servlet-name>AxisAdminServlet</servlet-name>

<servlet-class>org.apache.axis2.webapp.AxisAdminServlet</servlet-class>

</servlet>

<servlet-mapping><servlet>

<servlet-name>AxisServlet</servlet-name>

<servlet-class>org.apache.axis2.transport.http.AxisServlet</servlet-class>

<load-on-startup>1</load-on-startup>

</servlet>

<servlet>

<servlet-name>AxisAdminServlet</servlet-name>

<servlet-class>org.apache.axis2.webapp.AxisAdminServlet</servlet-class>

</servlet>

<servlet-mapping>

<servlet-name>AxisServlet</servlet-name>

<url-pattern>/servlet/AxisServlet</url-pattern>

</servlet-mapping>

<servlet-mapping>

<servlet-name>AxisServlet</servlet-name>

<url-pattern>*.jws</url-pattern>

</servlet-mapping>

<servlet-mapping>

<servlet-name>AxisServlet</servlet-name>

<url-pattern>/services/*</url-pattern>

</servlet-mapping>

<servlet-mapping>

<servlet-name>AxisAdminServlet</servlet-name>

<url-pattern>/axis2-admin/*</url-pattern>

</servlet-mapping>

 

 

<servlet-name>AxisServlet</servlet-name>

<url-pattern>/servlet/AxisServlet</url-pattern>

</servlet-mapping>

<servlet-mapping>

<servlet-name>AxisServlet</servlet-name>

<url-pattern>*.jws</url-pattern>

</servlet-mapping>

<servlet-mapping>

<servlet-name>AxisServlet</servlet-name>

<url-pattern>/services/*</url-pattern>

</servlet-mapping>

<servlet-mapping>

<servlet-name>AxisAdminServlet</servlet-name>

<url-pattern>/axis2-admin/*</url-pattern>

</servlet-mapping>

 

 

services的文件夹下面建立自己要发布的myService文件夹:

然后建立META-INF/services.xml

 

先编写一个需要发布的方法 (服务端)
public class MyServices {

public String sayHello(String name){

System.out.println("hello" + name);

return "hello";

}

}

 

需要发布的类和方法需要在services.xml中进行配置

<service name="MyService" targetNamespace="hwt_211">  <!-- 设置命名空间 -->

  <description>myservice Demo</description>  

   <schema schemaNamespace="hwt_211"/> <!-- 设置命名空间 -->

    <parameter name="ServiceClass">

       com.dg11185.ws.services.MyServices

    </parameter> 

     <messageReceivers>        

         <messageReceiver mep="http://www.w3.org/2004/08/wsdl/in-out"   

           class="org.apache.axis2.rpc.receivers.RPCMessageReceiver" />        

           <messageReceiver mep="http://www.w3.org/2004/08/wsdl/in-only"            

           class="org.apache.axis2.rpc.receivers.RPCInOnlyMessageReceiver" />    

     </messageReceivers>

</service>

 

客户端的调用公共方法见本文件夹的WebServiceClient..java

你可能感兴趣的:(Webservice基于xml的数据传输)