跳转到内容

XML - 数据交换/Web 服务/练习

来自维基教科书,开放的书籍,为开放的世界
    1. 使用以下 WSDL 文件创建 SOAP 请求和响应,用于获取两个国家之间的汇率。
  <?xml version="1.0"?>
  <definitions name="CurrencyExchangeService"
      targetNamespace="http://www.xmethods.net/sd/CurrencyExchangeService.wsdl"
      xmlns:tns="http://www.xmethods.net/sd/CurrencyExchangeService.wsdl" 
      xmlns:xsd="http://www.w3.org/2001/XMLSchema" 
      xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" 
      xmlns="http://schemas.xmlsoap.org/wsdl/">
 
         <message name="getRateRequest">
            <part name="country1" type="xsd:string"/>
	    <part name="country2" type="xsd:string"/>	
         </message>
         <message name="getRateResponse">
            <part name="Result" type="xsd:float"/>
         </message>
 
         <portType name="CurrencyExchangePortType">
            <operation name="getRate">
               <input message="tns:getRateRequest"/>
               <output message="tns:getRateResponse"/>
            </operation>
         </portType>
 
         <binding name="CurrencyExchangeBinding" type="tns:CurrencyExchangePortType">
            <soap:binding style="rpc" transport="http://schemas.xmlsoap.org/soap/http"/>
            <operation name="getRate">
               <soap:operation soapAction=""/>
               <input>
                  <soap:body use="encoded" namespace="urn:xmethods-CurrencyExchang" 
                      encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"/>
               </input>
               <output>
                  <soap:body use="encoded" namespace="urn:xmethods-CurrencyExchange" 
                      encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"/>
               </output>
            </operation>
         </binding>

         <service name="CurrencyExchangeService">
            <documentation>Returns the exchange rate between the two currencies</documentation>
            <port name="CurrencyExchangePort" binding="tns:CurrencyExchangeBinding">
               <soap:address location="http://services.xmethods.net:80/soap"/>
            </port>
         </service>

</definitions>

    2. 使用以下 SOAP 请求和响应文档创建 WSDL 文件,输入为城市,输出为该城市的人口。请求
  <?xml version="1.0" encoding="UTF-8" standalone="no"?/>
  <SOAP-ENV:Envelope
      SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" 
      xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/">
     
     <SOAP-ENV:Body>
        <m:getPopulation xmlns:m="urn:xmethods-Population">
           <city xsi:type="xsd:string">Athens </city>
        </m:getPopulation>
     </SOAP-ENV:Body>
     
  </SOAP-ENV:Envelope>

    响应
  <?xml version="1.0" encoding="UTF-8" standalone="no"?/>
  <SOAP-ENV:Envelope
      SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" 
      xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/">
     
     <SOAP-ENV:Body>
        <SOAPSDK1:getPopulationResponse xmlns:SOAPSDK1="urn:xmethods-Population">
           <Result xsi:type="xsd:float">140,372</Result>
        </SOAPSDK1:getPopulationResponse>
     </SOAP-ENV:Body>
     
  </SOAP-ENV:Envelope>

华夏公益教科书