发布webservice--axis

简介: [java] view plaincopyprint? package mule.webservice.service;  import javax.jws.WebParam;  import javax.jws.WebResult;  import javax.jws.WebService;  @WebService  public interf
  1. package mule.webservice.service; 
  2. import javax.jws.WebParam; 
  3. import javax.jws.WebResult; 
  4. import javax.jws.WebService; 
  5. @WebService 
  6. public interface Hello { 
  7.      
  8.     @WebResult(name="text"
  9.     public String sayHello(@WebParam(name="text")String name); 
  10.      
package mule.webservice.service; import javax.jws.WebParam; import javax.jws.WebResult; import javax.jws.WebService; @WebService public interface Hello { @WebResult(name="text") public String sayHello(@WebParam(name="text")String name); }

  1. package mule.webservice.service.impl; 
  2. import mule.webservice.service.Hello; 
  3. public class HelloImpl implements Hello { 
  4.     @Override 
  5.     public String sayHello(String name) { 
  6.         System.out.println("Hello," + name); 
  7.         return "Hello," + name; 
  8.     } 
package mule.webservice.service.impl; import mule.webservice.service.Hello; public class HelloImpl implements Hello { @Override public String sayHello(String name) { System.out.println("Hello," + name); return "Hello," + name; } }

配置config文件

  1. <?xml version="1.0" encoding="UTF-8"?> 
  2. <mule xmlns="http://www.mulesource.org/schema/mule/core/2.2" 
  3.     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
  4.     xmlns:soap="http://www.mulesource.org/schema/mule/soap/2.2" 
  5.     xmlns:axis="http://www.mulesource.org/schema/mule/axis/2.2" 
  6.     xmlns:vm="http://www.mulesource.org/schema/mule/vm/2.2" 
  7.     xsi:schemaLocation=" 
  8.     http://www.mulesource.org/schema/mule/core/2.2 http://www.mulesource.org/schema/mule/core/2.2/mule.xsd 
  9.     http://www.mulesource.org/schema/mule/soap/2.2 http://www.mulesource.org/schema/mule/soap/2.2/mule-soap.xsd 
  10.     http://www.mulesource.org/schema/mule/axis/2.2 http://www.mulesource.org/schema/mule/axis/2.2/mule-axis.xsd 
  11.     http://www.mulesource.org/schema/mule/vm/2.2 http://www.mulesource.org/schema/mule/vm/2.2/mule-vm.xsd 
  12.     ">    
  13.      
  14.     <model name="echoSample"> 
  15.          
  16.         <service name="testService"> 
  17.             <inbound> 
  18.                 <axis:inbound-endpoint address="http://localhost:65088/services"/> 
  19.             </inbound> 
  20.             <component class="mule.webservice.service.impl.HelloImpl"></component> 
  21.         </service> 
  22.     </model> 
  23. </mule> 
<?xml version="1.0" encoding="UTF-8"?> <mule xmlns="http://www.mulesource.org/schema/mule/core/2.2" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:soap="http://www.mulesource.org/schema/mule/soap/2.2" xmlns:axis="http://www.mulesource.org/schema/mule/axis/2.2" xmlns:vm="http://www.mulesource.org/schema/mule/vm/2.2" xsi:schemaLocation=" http://www.mulesource.org/schema/mule/core/2.2 http://www.mulesource.org/schema/mule/core/2.2/mule.xsd http://www.mulesource.org/schema/mule/soap/2.2 http://www.mulesource.org/schema/mule/soap/2.2/mule-soap.xsd http://www.mulesource.org/schema/mule/axis/2.2 http://www.mulesource.org/schema/mule/axis/2.2/mule-axis.xsd http://www.mulesource.org/schema/mule/vm/2.2 http://www.mulesource.org/schema/mule/vm/2.2/mule-vm.xsd "> <model name="echoSample"> <service name="testService"> <inbound> <axis:inbound-endpoint address="http://localhost:65088/services"/> </inbound> <component class="mule.webservice.service.impl.HelloImpl"></component> </service> </model> </mule>

测试类

  1. package mule.webservice.client; 
  2. import org.mule.api.MuleContext; 
  3. import org.mule.api.MuleException; 
  4. import org.mule.api.MuleMessage; 
  5. import org.mule.api.config.ConfigurationException; 
  6. import org.mule.api.lifecycle.InitialisationException; 
  7. import org.mule.context.DefaultMuleContextFactory; 
  8. import org.mule.module.client.MuleClient; 
  9. public class Client1 { 
  10.     public static void startMule(String config) { 
  11.         try
  12.             MuleContext muleContext;   
  13.             muleContext = new DefaultMuleContextFactory().createMuleContext(config);   
  14.             muleContext.start(); 
  15.         } catch (InitialisationException e) { 
  16.             e.printStackTrace(); 
  17.         } catch (ConfigurationException e) { 
  18.             e.printStackTrace(); 
  19.         } catch (MuleException e) { 
  20.             e.printStackTrace(); 
  21.         } 
  22.     } 
  23.      
  24.     public static void main(String[] args) { 
  25.         startMule("ws-config-1.xml"); 
  26.          
  27.         MuleClient client = null
  28.         try
  29.             client = new MuleClient(); 
  30.             String url = "axis:http://localhost:65088/services/testService?method=sayHello"
  31.             MuleMessage message = client.send(url, "zhuyoufeng", null); 
  32.             Object obj = message.getPayload(); 
  33.             System.out.println(obj.getClass().getName()); 
  34.             if (obj instanceof String) { 
  35.                 System.out.println(obj); 
  36.             } 
  37.         } catch (MuleException e) { 
  38.             e.printStackTrace(); 
  39.         } finally
  40.             client.dispose(); 
  41.         } 
  42.     } 

目录
相关文章
|
XML JavaScript Java
Axis调用Webservice添加SoupHeader
Axis调用Webservice添加SoupHeader
131 0
Axis调用Webservice添加SoupHeader
|
Java 应用服务中间件 Android开发
[WS]使用Axis发布简单的Web服务
使用Axis,要发布一个Web服务非常简单,简直不能再简单了,尽管看起来过程和相关代码有些长。我这个帖子里用到了这些软件:Axis 1.1、Eclipse 2.1和Eclipse的Tomcat插件2.2(Sysdeo Tomcat plugin)。
1329 0
|
应用服务中间件 数据格式 XML
[WS]使用Axis发布简单的Web服务(补充)
这篇帖子是对《使用Axis发布简单的Web服务》的补充。 可以看出,在Axis里书写deploy.wsdd并利用org.apache.axis.client.AdminClient发布,其主要工作就是把<service>标签中的内容添加在server-config.wsdd里,所以一般直接编辑server-config.wsdd文件会更方便一些。
960 0
|
测试技术 Java 应用服务中间件
|
Java 应用服务中间件 Android开发
|
Java 数据格式 XML