本文共 6035 字,大约阅读时间需要 20 分钟。
前面二篇文章都是以这个网址为基础进行分析的,http://www.ripedevelopment.com/webservices/LocalTime.asmx
但有时, 我们可能没有这个网址,只有一个wsdl文件, 怎么办呢, 其实读一下这个wsdl文件, 也是可以知道其中的接口以及调用方式。
我们先看一下上面这个网址的wsdl会是什么样的,
点击上面这个网址的左边: Service Description. 可以看到如下内容:
<?xml version="1.0" encoding="utf-16"?>
<definitions xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:soap12="http://schemas.xmlsoap.org/wsdl/soap12/" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/" xmlns:s="http://www.w3.org/2001/XMLSchema" xmlns:http="http://schemas.xmlsoap.org/wsdl/http/" xmlns:mime="http://schemas.xmlsoap.org/wsdl/mime/" xmlns:tm="http://microsoft.com/wsdl/mime/textMatching/" xmlns:s0="http://www.ripedev.com/" name="LocalTime" targetNamespace="http://www.ripedev.com/" xmlns="http://schemas.xmlsoap.org/wsdl/">
<types>
<xs:schema elementFormDefault="qualified" targetNamespace="http://www.ripedev.com/" xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="LocalTimeByZipCode">
<xs:complexType>
<xs:sequence>
<xs:element minOccurs="0" maxOccurs="1" name="ZipCode" type="xs:string"/>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="LocalTimeByZipCodeResponse">
<xs:complexType>
<xs:sequence>
<xs:element minOccurs="0" maxOccurs="1" name="LocalTimeByZipCodeResult" type="xs:string"/>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="string" nillable="true" type="xs:string"/>
</xs:schema>
</types>
<message name="LocalTimeByZipCodeSoapIn">
<part name="parameters" element="s0:LocalTimeByZipCode"/>
</message>
<message name="LocalTimeByZipCodeSoapOut">
<part name="parameters" element="s0:LocalTimeByZipCodeResponse"/>
</message>
<message name="LocalTimeByZipCodeHttpGetIn">
<part name="ZipCode" type="s:string"/>
</message>
<message name="LocalTimeByZipCodeHttpGetOut">
<part name="Body" element="s0:string"/>
</message>
<message name="LocalTimeByZipCodeHttpPostIn">
<part name="ZipCode" type="s:string"/>
</message>
<message name="LocalTimeByZipCodeHttpPostOut">
<part name="Body" element="s0:string"/>
</message>
<portType name="LocalTimeSoap">
<operation name="LocalTimeByZipCode">
<wsdl:documentation xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/">Returns local time for
a given zip code.</wsdl:documentation>
<input message="s0:LocalTimeByZipCodeSoapIn"/>
<output message="s0:LocalTimeByZipCodeSoapOut"/>
</operation>
</portType>
<portType name="LocalTimeSoap12">
<operation name="LocalTimeByZipCode">
<wsdl:documentation xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/">Returns local time for
a given zip code.</wsdl:documentation>
<input message="s0:LocalTimeByZipCodeSoapIn"/>
<output message="s0:LocalTimeByZipCodeSoapOut"/>
</operation>
</portType>
<portType name="LocalTimeHttpGet">
<operation name="LocalTimeByZipCode">
<wsdl:documentation xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/">Returns local time for
a given zip code.</wsdl:documentation>
<input message="s0:LocalTimeByZipCodeHttpGetIn"/>
<output message="s0:LocalTimeByZipCodeHttpGetOut"/>
</operation>
</portType>
<portType name="LocalTimeHttpPost">
<operation name="LocalTimeByZipCode">
<wsdl:documentation xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/">Returns local time for
a given zip code.</wsdl:documentation>
<input message="s0:LocalTimeByZipCodeHttpPostIn"/>
<output message="s0:LocalTimeByZipCodeHttpPostOut"/>
</operation>
</portType>
<binding name="LocalTimeSoap" type="s0:LocalTimeSoap">
<soap:binding transport="http://schemas.xmlsoap.org/soap/http"/>
<operation name="LocalTimeByZipCode">
<soap:operation soapAction="http://www.ripedev.com/LocalTimeByZipCode" style="document"/>
<input>
<soap:body use="literal"/>
</input>
<output>
<soap:body use="literal"/>
</output>
</operation>
</binding>
<binding name="LocalTimeSoap12" type="s0:LocalTimeSoap12">
<soap12:binding transport="http://schemas.xmlsoap.org/soap/http"/>
<operation name="LocalTimeByZipCode">
<soap12:operation soapAction="http://www.ripedev.com/LocalTimeByZipCode" style="document"/>
<input>
<soap12:body use="literal"/>
</input>
<output>
<soap12:body use="literal"/>
</output>
</operation>
</binding>
<binding name="LocalTimeHttpGet" type="s0:LocalTimeHttpGet">
<http:binding verb="GET"/>
<operation name="LocalTimeByZipCode">
<http:operation location="/LocalTimeByZipCode"/>
<input>
<http:urlEncoded/>
</input>
<output>
<mime:mimeXml part="Body"/>
</output>
</operation>
</binding>
<binding name="LocalTimeHttpPost" type="s0:LocalTimeHttpPost">
<http:binding verb="POST"/>
<operation name="LocalTimeByZipCode">
<http:operation location="/LocalTimeByZipCode"/>
<input>
<mime:content type="application/x-www-form-urlencoded"/>
</input>
<output>
<mime:mimeXml part="Body"/>
</output>
</operation>
</binding>
<service name="LocalTime">
<wsdl:documentation xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/">Provides local time for
the supplied zip code</wsdl:documentation>
<port name="LocalTimeSoap" binding="s0:LocalTimeSoap">
<soap:address location="http://www.ripedevelopment.com/webservices/LocalTime.asmx"/>
</port>
<port name="LocalTimeSoap12" binding="s0:LocalTimeSoap12">
<soap12:address location="http://www.ripedevelopment.com/webservices/LocalTime.asmx"/>
</port>
<port name="LocalTimeHttpGet" binding="s0:LocalTimeHttpGet">
<http:address location="http://www.ripedevelopment.com/webservices/LocalTime.asmx"/>
</port>
<port name="LocalTimeHttpPost" binding="s0:LocalTimeHttpPost">
<http:address location="http://www.ripedevelopment.com/webservices/LocalTime.asmx"/>
</port>
</service>
</definitions>
这里我们先只看最后几行, 可以看出, 上面分别针对Soap, Soap12, HttpGet, HttpPost有不同的地址调用,
<port name="LocalTimeSoap" binding="s0:LocalTimeSoap">
<soap:address location="http://www.ripedevelopment.com/webservices/LocalTime.asmx"/>
</port>
如上面的这个, 我们可以看到后面的地址就是我们之前使用到的请求地址,
然后为了看懂这个wsdl文件,我们可以去看看这个教程,http://www.w3school.com.cn/wsdl/index.asp把这个看明白了,估计看上面这个wsdl就不是问题了。
PS: 作为前端开发者, 实际上是不太需要知道上面这些过程的, 因为一般情况下, 后台服务器开发人员都会把如何调用的方式告诉前端开发者,不过如果理解了这整个过程,应该会很有好外。
再啰嗦一下, 通过前面的教程, 我们也发现了这个SOAP的网页这么好用,有这么多的信息, 还可以在线测试,还可以把如何请求都举例子,想想可能觉得要发布一个web service要作的工作还真多,其实不然。 这个页面都可以直接通过微软的发布直接生成,不需要后台人员去添加例子什么的。是不是挺方便呢。
转载地址:http://ahwpi.baihongyu.com/