| Googleを追いかけろ! |
| |
| . | ||
| home >> Soap Services >> Tutorial: Accessing a Soap Service | ||
var wsdl = SoapService.wsdl("http://www.webservicex.net/geoipservice.asmx?wsdl");
|
Logger.log(wsdl.getServiceNames()); |
<wsdl:service name="GeoIPService"> |
var geoService = wsdl.getService("GeoIPService");
|
var geoService = wsdl.getGeoIPService(); |
Logger.log(geoService.getOperationNames()); |
POST /geoipservice.asmx HTTP/1.1
Host: www.webservicex.net
Content-Type: text/xml; charset=utf-8
Content-Length: length
SOAPAction: "http://www.webservicex.net/GetGeoIP"
<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Body>
<GetGeoIP xmlns="http://www.webservicex.net">
<IPAddress>72.14.228.129</IPAddress>
</GetGeoIP>
</soap:Body>
</soap:Envelope>
|
<GetGeoIP xmlns="http://www.webservicex.net">
<IPAddress>72.14.228.129</IPAddress>
</GetGeoIP>
|
var param = Xml.element("GetGeoIP", [
Xml.attribute("xmlns", "http://www.webservicex.net"),
Xml.element("IPAddress", [
"72.14.228.129"
])
]);
|
var envelope = geoService.getSoapEnvelope("GetGeoIP", param)
Logger.log(envelope);
|
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
<SOAP-ENV:Body>
<GetGeoIP xmlns="http://www.webservicex.net">
<IPAddress>72.14.228.129</IPAddress>
</GetGeoIP>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
|
var result = geoService.invokeOperation("GetGeoIP", [param]);
|
var result = geoService.GetGeoIP(param); |
Logger.log(result.toXmlString()); |
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<GetGeoIPResponse xmlns="http://www.webservicex.net">
<GetGeoIPResult>
<ReturnCode>1</ReturnCode>
<IP>72.14.228.129</IP>
<ReturnCodeDetails>Record Found</ReturnCodeDetails>
<CountryName>UNITED STATES</CountryName>
<CountryCode>US</CountryCode>
</GetGeoIPResult>
</GetGeoIPResponse>
|
Logger.log(result.Envelope.Body.GetGeoIPResponse.GetGeoIPResult.CountryCode.Text); |
function determineCountryFromIP(ipAddress) {
var wsdl = SoapService.wsdl("http://www.webservicex.net/geoipservice.asmx?wsdl");
var geoService = wsdl.getGeoIPService();
var param = Xml.element("GetGeoIP", [
Xml.attribute("xmlns", "http://www.webservicex.net"),
Xml.element("IPAddress", [
ipAddress
])
]);
var result = geoService.GetGeoIP(param);
return result.Envelope.Body.GetGeoIPResponse.GetGeoIPResult.CountryCode.Text;
}
|