码迷,mamicode.com
首页 > 其他好文 > 详细

Axis1.4之即时发布服务

时间:2015-10-28 01:15:18      阅读:362      评论:0      收藏:0      [点我收藏+]

标签:

下载axis1.4开发包,解压开发包,将webapps目录下的axis文件夹拷贝到tomcat的webapps目录下。启动tomcat,在浏览器输入http://localhost:8080/axis得到如下页面:

技术分享

实用axis的发布服务平台,创建和发布WebService服务有两种方式:即时发布和定制发布。即时发布服务很少用,但是为了知识体系的完整性,这里还是讲一下。本篇文章只讲即时发布服务。

写一个没有包的Java类HelloWS.java:

public class HelloWS{  
  
    public String test(String a ,String b){  
  
        String result = "a="+a+",b="+b;  
        return "server response ok ,u send "+result;  
    }  
}  

然后将此文件拷贝到tomcat_home\webapps\axis目录下,并将文件后缀改为jws。在浏览器输入http://localhost:8080/axis/HelloWS.jws得到如下页面:

技术分享

点击链接,浏览器展现一个wsdl文档:

 1 <wsdl:definitions xmlns:apachesoap="http://xml.apache.org/xml-soap" xmlns:impl="http://localhost:8080/axis/HelloWS.jws" xmlns:intf="http://localhost:8080/axis/HelloWS.jws" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns:wsdlsoap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" targetNamespace="http://localhost:8080/axis/HelloWS.jws">
 2 <!--
 3 WSDL created by Apache Axis version: 1.4
 4 Built on Apr 22, 2006 (06:55:48 PDT)
 5 -->
 6 <wsdl:message name="testResponse">
 7 <wsdl:part name="testReturn" type="xsd:string"/>
 8 </wsdl:message>
 9 <wsdl:message name="testRequest">
10 <wsdl:part name="a" type="xsd:string"/>
11 <wsdl:part name="b" type="xsd:string"/>
12 </wsdl:message>
13 <wsdl:portType name="HelloWS">
14 <wsdl:operation name="test" parameterOrder="a b">
15 <wsdl:input message="impl:testRequest" name="testRequest"/>
16 <wsdl:output message="impl:testResponse" name="testResponse"/>
17 </wsdl:operation>
18 </wsdl:portType>
19 <wsdl:binding name="HelloWSSoapBinding" type="impl:HelloWS">
20 <wsdlsoap:binding style="rpc" transport="http://schemas.xmlsoap.org/soap/http"/>
21 <wsdl:operation name="test">
22 <wsdlsoap:operation soapAction=""/>
23 <wsdl:input name="testRequest">
24 <wsdlsoap:body encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" namespace="http://DefaultNamespace" use="encoded"/>
25 </wsdl:input>
26 <wsdl:output name="testResponse">
27 <wsdlsoap:body encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" namespace="http://localhost:8080/axis/HelloWS.jws" use="encoded"/>
28 </wsdl:output>
29 </wsdl:operation>
30 </wsdl:binding>
31 <wsdl:service name="HelloWSService">
32 <wsdl:port binding="impl:HelloWSSoapBinding" name="HelloWS">
33 <wsdlsoap:address location="http://localhost:8080/axis/HelloWS.jws"/>
34 </wsdl:port>
35 </wsdl:service>
36 </wsdl:definitions>

这就已经发布了服务。下面我们测试一下:我们新建一个Java工程,导入axis1.4开发包下的所有jar,然后写一个测试类Client:

 1 package com.client;  
 2   
 3 import java.rmi.RemoteException;  
 4   
 5 import javax.xml.namespace.QName;  
 6 import javax.xml.rpc.ServiceException;  
 7   
 8 import org.apache.axis.client.Call;  
 9 import org.apache.axis.client.Service;  
10   
11 public class Client {  
12   
13     public static void main(String[] args) throws ServiceException, RemoteException {  
14   
15         String url = "http://localhost:8080/axis/HelloWS.jws";  
16         Service service = new Service();  
17         Call call = (Call) service.createCall();  
18         call.setTargetEndpointAddress(url);  
19         call.setOperationName(new QName(url,"test"));  
20         String result = (String) call.invoke(new Object[]{"Tomcat","Jetty"});  
21         System.out.println(result);  
22     }  
23   
24 }  

运行,控制台输出:

技术分享

这就是即时发布。即时发布在实际应用中几乎不用。下篇文章我们讨论如何利用Apache提供的axis服务平台发布定制服务。

  

Axis1.4之即时发布服务

标签:

原文地址:http://www.cnblogs.com/build-up/p/4916022.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!