编程教程
您现在的位置: 中国个人站长站 >> 网络编程 >> ASP.NET教程 >> 教程正文 WSDL规则与示例(2)
推荐位

WSDL规则与示例(2)

中国个人站长站 ASP.NET教程 点击数: 更新时间:2007-7-9 5:16:42

看看两段简单的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:
<?xml version="1.0" encoding="UTF-8"?>
<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">
//自定义类型
 <wsdl:types>
  <schema targetNamespace="http://businessEngine.hongsoft.com" xmlns="http://www.w3.org/2001/XMLSchema">
   <import namespace="http://schemas.xmlsoap.org/soap/encoding/"/>
   //复合类型
   <complexType name="CatDTO">
    <sequence>
     <element name="id" type="xsd:long"/>
     <element name="name" nillable="true" type="xsd:string"/>
    </sequence>
   </complexType>
   <element name="CatDTO" nillable="true" type="intf:CatDTO"/>
  </schema>
 </wsdl:types>

   <wsdl:message name="echoResponse">

      <wsdl:part name="echoReturn" type="xsd:string"/>

   </wsdl:message>
   //表示复合类型的消息

   <wsdl:message name="echoRequest">

      <wsdl:part name="cd" type="intf:CatDTO"/>

   </wsdl:message>
   //portType雷同一个类

   <wsdl:portType name="Test">

      <wsdl:operation name="echo" parameterOrder="cd">

         <wsdl:input message="intf:echoRequest" name="echoRequest"/>

         <wsdl:output message="intf:echoResponse" name="echoResponse"/>

      </wsdl:operation>

   </wsdl:portType>
   //与实现进行绑定,这里用SOAP方式

   <wsdl:binding name="TestSoapBinding" type="intf:Test">

      <wsdlsoap:binding style="rpc" transport="http://schemas.xmlsoap.org/soap/http"/>

      <wsdl:operation name="echo">

         <wsdlsoap:operation soapAction=""/>

         <wsdl:input name="echoRequest">

            <wsdlsoap:body encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" namespace="http://businessEngine.hongsoft.com" use="encoded"/>

         </wsdl:input>

         <wsdl:output name="echoResponse">

            <wsdlsoap:body encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" namespace="http://businessEngine.hongsoft.com" use="encoded"/>

         </wsdl:output>

      </wsdl:operation>

   </wsdl:binding>
  //用于发布服务

   <wsdl:service name="TestService">

      <wsdl:port binding="intf:TestSoapBinding" name="Test">

         <wsdlsoap:address location="http://localhost:8080/hongsoft/services/Test"/>

      </wsdl:port>

   </wsdl:service>

</wsdl:definitions>

教程录入:swh    责任编辑:swh 
个人站长站与你风雨同舟!
本站所提供的资源均来源于互联网,如有侵权行为,请与本站管理员联系,我们会第一时间删除!
·如果您发现《WSDL规则与示例(2)》文章有错误,也请通知我们修改!
联系邮箱chinageren#126.com,谢谢支持!
站内搜索:
广告服务 | 友情链接 | 联系我们 | 免责声明 | 用户留言 | 网站导航
版权所有:中国个人站长站 2007-2008 未经授权禁止复制或建立镜像 客服QQ号:112731235
copyright © 2007-2008 www.ChinaGeRen.com online services. all rights reserved. 苏ICP备05000059号