看看两段简单的JAVA代码,我们用它作为WSDL的服务实现代码:
//CatDTO.java
public class CatDTO
{
private long id;
private String name;
public long getId()
{
return id;
}
public String getName()
{
return name;
}
public void setId(long id)
{
this.id = id;
}
public void setName(String name)
{
this.name = name;
}
}
//Test.java
public class Test
{
public String echo(CatDTO cd){
return "Hello " + cd.getName();
}
}
然后看看用它导出的WSDL:
1<wsdl:definitions targetnamespace=" http://businessEngine.hongsoft.com " xmlns=" http://schemas.xmlsoap.org/wsdl/ " xmlns:apachesoap=" http://xml.apache.org/xml-soap " xmlns:impl=" http://businessEngine.hongsoft.com-impl " xmlns:intf=" http://businessEngine.hongsoft.com " 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 ">
2//自定义类型
3<wsdl:types>
4<schema targetnamespace=" http://businessEngine.hongsoft.com " xmlns=" http://www.w3.org/2001/XMLSchema ">
5<import namespace=" http://schemas.xmlsoap.org/soap/encoding/">
6//复合类型
7<complextype name="CatDTO">
8<sequence>
9<element name="id" type="xsd:long"></element>
10<element name="name" nillable="true" type="xsd:string"></element>
11</sequence>
12</complextype>
13<element name="CatDTO" nillable="true" type="intf:CatDTO"></element>
14</import></schema>
15</wsdl:types>
16<wsdl:message name="echoResponse">
17<wsdl:part name="echoReturn" type="xsd:string"></wsdl:part>
18</wsdl:message>
19//表示复合类型的消息
20
21<wsdl:message name="echoRequest">
22<wsdl:part name="cd" type="intf:CatDTO"></wsdl:part>
23</wsdl:message>
24//portType雷同一个类
25
26<wsdl:porttype name="Test">
27<wsdl:operation name="echo" parameterorder="cd">
28<wsdl:input message="intf:echoRequest" name="echoRequest"></wsdl:input>
29<wsdl:output message="intf:echoResponse" name="echoResponse"></wsdl:output>
30</wsdl:operation>
31</wsdl:porttype>
32//与实现进行绑定,这里用SOAP方式
33
34<wsdl:binding name="TestSoapBinding" type="intf:Test">
35<wsdlsoap:binding style="rpc" transport=" http://schemas.xmlsoap.org/soap/http">
36<wsdl:operation name="echo">
37<wsdlsoap:operation soapaction=""></wsdlsoap:operation>
38<wsdl:input name="echoRequest">
39<wsdlsoap:body encodingstyle=" http://schemas.xmlsoap.org/soap/encoding/ " namespace=" http://businessEngine.hongsoft.com " use="encoded"></wsdlsoap:body>
40</wsdl:input>
41<wsdl:output name="echoResponse">
42<wsdlsoap:body encodingstyle=" http://schemas.xmlsoap.org/soap/encoding/ " namespace=" http://businessEngine.hongsoft.com " use="encoded"></wsdlsoap:body>
43</wsdl:output>
44</wsdl:operation>
45</wsdlsoap:binding></wsdl:binding>
46//用于发布服务
47
48<wsdl:service name="TestService">
49<wsdl:port binding="intf:TestSoapBinding" name="Test">
50<wsdlsoap:address location=" http://localhost:8080/hongsoft/services/Test">
51</wsdlsoap:address></wsdl:port>
52</wsdl:service>
53</wsdl:definitions>