WSDL - 示例
下面给出一个 WSDL 文件,用于演示一个简单的 WSDL 程序。
我们假设服务提供了一个公开可用的函数,名为 sayHello。此函数需要一个字符串参数并返回一个字符串问候语。例如,如果您传递参数 world,则服务函数 sayHello 将返回问候语"Hello, world!"。
示例
HelloService.wsdl 文件的内容 −
<definitions name = "HelloService" targetNamespace = "http://www.examples.com/wsdl/HelloService.wsdl" xmlns = "http://schemas.xmlsoap.org/wsdl/" xmlns:soap = "http://schemas.xmlsoap.org/wsdl/soap/" xmlns:tns = "http://www.examples.com/wsdl/HelloService.wsdl" xmlns:xsd = "http://www.w3.org/2001/XMLSchema"> <message name = "SayHelloRequest"> <part name = "firstName" type = "xsd:string"/> </message> <message name = "SayHelloResponse"> <part name = "greeting" type = "xsd:string"/> </message> <portType name = "Hello_PortType"> <operation name = "sayHello"> <input message = "tns:SayHelloRequest"/> <output message = "tns:SayHelloResponse"/> </operation> </portType> <binding name = "Hello_Binding" type = "tns:Hello_PortType"> <soap:binding style = "rpc" transport = "http://schemas.xmlsoap.org/soap/http"/> <operation name = "sayHello"> <soap:operation soapAction = "sayHello"/> <input> <soap:body encodingStyle = "http://schemas.xmlsoap.org/soap/encoding/" namespace = "urn:examples:helloservice" use = "encoded"/> </input> <output> <soap:body encodingStyle = "http://schemas.xmlsoap.org/soap/encoding/" namespace = "urn:examples:helloservice" use = "encoded"/> </output> </operation> </binding> <service name = "Hello_Service"> <documentation>WSDL File for HelloService</documentation> <port binding = "tns:Hello_Binding" name = "Hello_Port"> <soap:address location = "http://www.examples.com/SayHello/" /> </port> </service> </definitions>
示例分析
Definitions − HelloService
Type − 使用内置数据类型,它们在 XMLSchema 中定义。
Message −
sayHelloRequest − firstName 参数
sayHelloresponse − Greeting 返回值
Port Type − sayHello 操作由请求和响应服务组成。
Binding − 使用 SOAP HTTP 传输协议的方向。
Service −服务可在 http://www.examples.com/SayHello/ 获得
Port − 将绑定与 URI http://www.examples.com/SayHello/ 关联,可从该 URI 访问正在运行的服务。