引言:复杂的参数如结构数组可以用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;
}
}
1.3. 测试WSDL
下面我们就可以测试该Web服务了,打开浏览器并输入刚刚创建的文件名对应的URL地址 http://localhost:8080/axis/soapTest.jws 浏览器显示如下结果:
|
点击页面上的链接查看该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">--> 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>