xmlhack.ru logo
>> статьи на xmlhack.ru

Примеры к статье «DOM для Web-сервисов, часть 1»

В закладки:   Del.icio.us   reddit

Примеры к статье «DOM для Web-сервисов, часть 1».

Пример 1.

<?xml version="1.0" encoding="utf-8"?> <definitions xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/" targetNamespace="http://www.cityportal.com/" xmlns="http://schemas.xmlsoap.org/wsdl/"> <message name="CityWeatherReportRequest"> <part name="CityName" type="xsd:string" /> </message> <message name="CityWeatherReportResponse"> <part name="weatherReport" type="xsd:string"/> </message> <portType name="WeatherServicePortType"> <operation name="GetCityWeatherReport"> <documentation> Provide the name of a city and this method will return the most recent weather report of that city. </documentation> <input message="CityWeatherReportRequest"/> <output message="CityWeatherReportResponse"/> </operation> </portType> <binding name="WeatherServiceBinding" type="WeatherServicePortType"> <soap:binding style="rpc" transport="http://schemas.xmlsoap.org/soap/http"/> <operation name="GetCityWeatherReport"> <soap:operation soapAction="http://www.cityportal.com/webservice/weatherservice/weatherReport" /> <input> <soap:body encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" namespace="http://www.cityportal.com/webservice/weatherservice/" use="encoded"/> </input> <output> <soap:body encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" namespace="http://www.cityportal.com/webservice/weatherservice/" use="encoded"/> </output> </operation> </binding> <service name="WeatherService"> <documentation> This weather update service provides weather reports of all major cities of the world. </documentation> <port name="WeatherServicePortType" binding="WeatherServiceBinding"> <soap:address location="http://www.cityportal.com/webservices/weatherservice"/> </port> </service> </definitions>

Пример 2.

<html> <body> <p> <h3>WeatherService</h3> This weather update service provides weather reports of all major cities of the world. </p> <table> <form action="http://www.cityportal.com/webserviceuserinterfcae/weatherservice.asp"> <tr> <td> <b>Operation:</b> </td> <td>GetCityWeatherReport</td> </tr> <tr> <td> <b>Description:</b> </td> <td> Provide the name of a city and this method will return the most recent weather report of that city. </td> </tr> <tr> <td> <b>City Name:</b> </td> <td><input type="text" name="CityName"/></td> </tr> <tr> <td> </td> <td> <input type="submit" value="Submit" /> </td> </tr> </form> </table> </body> </html>

Пример 3.

<?xml version="1.0"?> <SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/1999/XMLSchema"> <SOAP-ENV:Body> <w:GetCityWeatherReport xmlns:w="http://www.cityportal.com"> <w:CityName type="xsd:string">Karachi</w:CityName> </w:GetCityWeatherReport> </SOAP-ENV:Body> </SOAP-ENV:Envelope>

Пример 4.

<html> <head> <title>WeatherService...</title> <script language="JavaScript"> function FindServiceDocumentation() { var xmlDoc = new ActiveXObject("MSXML2.DOMDocument.4.0"); var definitionsElement; var serviceElement; var documentationElement; xmlDoc.load("WeatherService.wsdl"); if (xmlDoc.parseError.errorCode != 0) alert("WSDL File parsing error occurred...code="+xmlDoc.parseError.errorCode); else { definitionsElement = xmlDoc.documentElement; if (definitionsElement.nodeName!="definitions") alert ("Invalid WSDL file... [no root <definitions> element]"); else { serviceElement = definitionsElement.getElementsByTagName("service").item(0); if (serviceElement == null) alert ("No service Element found!!"); else { var documentationElement = serviceElement.getElementsByTagName("documentation").item(0); if (documentationElement == null) alert ("No documentation element found!!"); else alert (documentationElement.firstChild.nodeValue); }//else if (serviceElement == null) }//else if (definitionsElement.nodeName!="definitions") }// else if (xmlDoc.parseError.errorCode != 0) } // FindServiceDocumentation </script> </head> <body onload="FindServiceDocumentation()"> </body> </html>