AXIS生成WSDL(複雜參數篇)

引言:複雜的參數如結構數組可以用javabean來表示。
 
 
1.   java代碼
1.1.JavaBean的生成
複雜的SOAP接口需要用Bean做輸入輸出的參數,步驟如下:
(1)         寫javabean的代碼,如resultBean.java。
(2)         編譯生成resultBean.class
(3)      把該class文件拷貝到C:/Tomcat/webapps/axis/WEB-INF/classes
文件內容如下:
class resultBean{
   private String PhoneNo;
   private String UserName;
      public void setPhoneNo(String No)
   {
       PhoneNo = No;
   }
   public void setUserName(String Name)
   {
       UserName = Name;
   }
   public String getPhoneNo()
   {
       return PhoneNo ;
   }
   public String getUserName()
   {
       return UserName;
   }
}
1.2. 寫WEB service的java
(1)         寫java類文件,文件後綴.jws,例如:soapTest.jws
(2)         寫完後拷貝到C:/Tomcat/webapps/axis
 
       文件內容如下(soapTest.jws)
public class soapTest{
   public String Hello(String name)
   {
       if (name == null)
            name = "Tom";
       return "Wlelcome " + name +" to beijing! ";
   }
   public resultBean getVOIPParams(String lineno)
   {
      resultBean rst = new resultBean();
      if (lineno == "1")
      {
          rst.setPhoneNo("123456");
          rst.setUserName("zhang");
      }
      return rst;
       }
}
 
下面我們就可以測試該Web服務了,打開瀏覽器並輸入剛剛創建的文件名對應的URL地址 http://localhost:8080/axis/soapTest.jws 瀏覽器顯示如下結果:
 
 
There is a Web Service here
      
        Click to see the WSDL 
          
 
點擊頁面上的鏈接查看該Web服務對應的WSDL信息如下所示:
 <?xml version="1.0" encoding="UTF-8" ?>
- <wsdl:definitions targetNamespace="http://localhost:8080/axis/soapTest.jws" xmlns:apachesoap="http://xml.apache.org/xml-soap" xmlns:impl="http://localhost:8080/axis/soapTest.jws" xmlns:intf="http://localhost:8080/axis/soapTest.jws" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/" xmlns:tns1="http://DefaultNamespace" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns:wsdlsoap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
- <!--WSDL created by Apache Axis version: 1.4Built on Apr 22, 2006 (06:55:48 PDT)
  --> f(clean);
- <wsdl:types>
- <schema targetNamespace="http://DefaultNamespace" xmlns="http://www.w3.org/2001/XMLSchema">
  <import namespace="http://schemas.xmlsoap.org/soap/encoding/" />
- <complexType name="resultBean">
- <sequence>
  <element name="phoneNo" nillable="true" type="xsd:string" />
  <element name="userName" nillable="true" type="xsd:string" />
  </sequence>
  </complexType>
  </schema>
  </wsdl:types>
- <wsdl:message name="getVOIPParamsResponse">
  <wsdl:part name="getVOIPParamsReturn" type="tns1:resultBean" />
  </wsdl:message>
- <wsdl:message name="getVOIPParamsRequest">
  <wsdl:part name="lineno" type="xsd:string" />
  </wsdl:message>
- <wsdl:message name="HelloRequest">
  <wsdl:part name="name" type="xsd:string" />
  </wsdl:message>
- <wsdl:message name="HelloResponse">
  <wsdl:part name="HelloReturn" type="xsd:string" />
  </wsdl:message>
- <wsdl:portType name="soapTest">
- <wsdl:operation name="Hello" parameterOrder="name">
  <wsdl:input message="impl:HelloRequest" name="HelloRequest" />
  <wsdl:output message="impl:HelloResponse" name="HelloResponse" />
  </wsdl:operation>
- <wsdl:operation name="getVOIPParams" parameterOrder="lineno">
  <wsdl:input message="impl:getVOIPParamsRequest" name="getVOIPParamsRequest" />
  <wsdl:output message="impl:getVOIPParamsResponse" name="getVOIPParamsResponse" />
  </wsdl:operation>
  </wsdl:portType>
- <wsdl:binding name="soapTestSoapBinding" type="impl:soapTest">
  <wsdlsoap:binding style="rpc" transport="http://schemas.xmlsoap.org/soap/http" />
- <wsdl:operation name="Hello">
  <wsdlsoap:operation soapAction="" />
- <wsdl:input name="HelloRequest">
  <wsdlsoap:body encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" namespace="http://DefaultNamespace" use="encoded" />
  </wsdl:input>
- <wsdl:output name="HelloResponse">
  <wsdlsoap:body encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" namespace="http://localhost:8080/axis/soapTest.jws" use="encoded" />
  </wsdl:output>
  </wsdl:operation>
- <wsdl:operation name="getVOIPParams">
  <wsdlsoap:operation soapAction="" />
- <wsdl:input name="getVOIPParamsRequest">
  <wsdlsoap:body encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" namespace="http://DefaultNamespace" use="encoded" />
  </wsdl:input>
- <wsdl:output name="getVOIPParamsResponse">
  <wsdlsoap:body encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" namespace="http://localhost:8080/axis/soapTest.jws" use="encoded" />
  </wsdl:output>
  </wsdl:operation>
  </wsdl:binding>
- <wsdl:service name="soapTestService">
- <wsdl:port binding="impl:soapTestSoapBinding" name="soapTest">
  <wsdlsoap:address location="http://10.9.59.165:8080/axis/soapTest.jws" />
  </wsdl:port>
  </wsdl:service>
  </wsdl:definitions>

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章