AXIS2实例6:wsdl2java(object 方法)

1. server

1) 修改HelloService.wsdl

<?xml version="1.0" encoding="UTF-8"?>

<definitions xmlns="http://schemas.xmlsoap.org/wsdl/" xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:tns="http://cn.com.demo.axis/HelloService" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsd1="http://cn.com.demo.axis/xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" targetNamespace="http://cn.com.demo.axis/HelloService" name="HelloServiceService">
 <types>
  <schema targetNamespace="http://cn.com.demo.axis/xsd" xmlns="http://www.w3.org/2001/XMLSchema" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" elementFormDefault="qualified">
   <complexType name="SOAPUser">
    <all>
     <element name="userId" type="xsd:int"/>
     <element name="userName" type="xsd:string"/>
     <element name="userPassword" type="xsd:string"/>
    </all>
   </complexType>
   <!-- string -->
   <element name="echoStringParam" type="xsd:string"/>
   <element name="echoStringReturn" type="xsd:string"/>

   <!-- object: tbuser -->
   <element name="echoUserParam" type="xsd1:SOAPUser"/>
   <element name="echoUserReturn" type="xsd1:SOAPUser"/>
  </schema>
 </types>
 <message name="echoString">
  <part name="stringParam" element="xsd1:echoStringParam"/>
 </message>
 <message name="echoStringResponse">
  <part name="result" element="xsd1:echoStringReturn"/>
 </message>

 <message name="echoUser">
  <part name="a" element="xsd1:echoUserParam"/>
 </message>
 <!-- object: tbuser -->
 <message name="echoUserResponse">
  <part name="result" element="xsd1:echoUserReturn"/>
 </message>

 <portType name="HelloServicePortType">
  <operation name="echoString">
   <input name="echoString" message="tns:echoString"/>
   <output name="echoStringResponse" message="tns:echoStringResponse"/>
  </operation>
  <!-- object: tbuser -->
  <operation name="echoUser">
   <input name="echoUser" message="tns:echoUser"/>
   <output name="echoUserResponse" message="tns:echoUserResponse"/>
  </operation>

 </portType>

 <binding name="HelloServicePortBinding" type="tns:HelloServicePortType">
  <soap:binding style="document" transport="http://schemas.xmlsoap.org/soap/http"/>
  <operation name="echoString">
   <soap:operation soapAction="echoString" style="document"/>
   <input>
    <soap:body use="literal" namespace="http://cn.com.demo.axis/HelloService"/>
   </input>
   <output>
    <soap:body use="literal" namespace="http://cn.com.demo.axis/HelloService"/>
   </output>
  </operation>
  <operation name="echoUser">
   <soap:operation soapAction="echoUser" style="document"/>
   <input>
    <soap:body use="literal" namespace="
http://cn.com.demo.axis/HelloService"/>
   </input>
   <output>
    <soap:body use="literal" namespace="
http://cn.com.demo.axis/HelloService"/>
   </output>
  </operation>
 </binding>
 
 <service name="HelloServiceService">
  <port name="HelloServicePort" binding="tns:HelloServicePortBinding">
   <soap:address location="http://cn.com.demo.axis/stkv3/wsdl/HelloService.wsdl"/>
  </port>
 </service>
</definitions>

** 粗体部分为增加

 

路径: D:/axis151/mysamples/src/保留原来写的cn.com.demo.axis.HelloServiceServiceSkelton.java, Client.java, 其他文件删除。

D:/axis151/mysamples/wsdl2java -uri HelloService.wsdl -ss -sd -d xmlbeans -o . -p cn.com.demo.axis

生成新的服务端的代码

 

修改 cn.com.demo.axis.HelloServiceServiceSkelton.java


/**
 * HelloServiceServiceSkeleton.java
 *
 * This file was auto-generated from WSDL
 * by the Apache Axis2 version: 1.5.1  Built on : Oct 19, 2009 (10:59:00 EDT)
 */
    package cn.com.demo.axis;
    /**
     *  HelloServiceServiceSkeleton java skeleton for the axisService
     */
  import axis.demo.com.cn.xsd.*;
    public class HelloServiceServiceSkeleton{
       
        
        /**
         * Auto generated method signature
         *
                                     * @param echoStringParam
         */
       
                 public axis.demo.com.cn.xsd.EchoStringReturnDocument echoString
                  (
                  axis.demo.com.cn.xsd.EchoStringParamDocument echoStringParam
                  )
            {
                //TODO : fill this with the necessary business logic
    EchoStringReturnDocument doc = EchoStringReturnDocument.Factory.newInstance();
    doc.setEchoStringReturn(echoStringParam.getEchoStringParam());
                return doc;
                //throw new  java.lang.UnsupportedOperationException("Please implement " + this.getClass().getName() + "#echoString");
        }

  public axis.demo.com.cn.xsd.EchoUserReturnDocument echoUser
                  (
                  axis.demo.com.cn.xsd.EchoUserParamDocument echoStringParam
                  )
            {
                //TODO : fill this with the necessary business logic
    EchoUserReturnDocument doc = EchoUserReturnDocument.Factory.newInstance();
    doc.setEchoUserReturn(echoStringParam.getEchoUserParam());
                return doc;
                //throw new  java.lang.UnsupportedOperationException("Please implement " + this.getClass().getName() + "#echoString");
        }
    
    }

** 粗体为添加部分

 

2. client

D:/axis151/mysamples/wsdl2java -uri HelloService.wsdl -d xmlbeans -o . -p cn.com.demo.axis

生成新的客户端的代码

 

 

修改 Client.java, 在main里,增加

String url = "http://localhost/axis2/services/HelloServiceService";
  try{
   
   HelloServiceServiceStub stub = new HelloServiceServiceStub(null,url);
   

   EchoUserParamDocument uRequest = EchoUserParamDocument.Factory.newInstance();
   SOAPUser user = SOAPUser.Factory.newInstance();
   user.setUserName("fj");
   user.setUserPassword("fj");

   uRequest.setEchoUserParam(user);

   EchoUserReturnDocument doc = stub.echoUser(uRequest);
   SOAPUser retUser = uRequest.getEchoUserParam();
   System.out.println(retUser.getUserName());
   System.out.println(retUser.getUserPassword());
   
   
  }catch(Exception ex){
   ex.printStackTrace();
  }
 

3. build

路径:

D:/axis151/mysamples/ant clean

D:/axis151/mysamples/ant jar.all

生成的服务端.aar文件放置到%tomcat_home%/webapp/axis2/web-inf/services下。

 

 

5. test

D:/axis151/mysamples/ant run.client

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值