|
Last-modified: 2003-12-30 (火) 20:02:08 (7429d)
Microsoft SOAP Toolkitを利用するMicrosoft SOAP ToolkitをCOMとして利用すると、WSHで簡単にWebサービスリクエスタが作れます。ちなみにWindowsXPはSOAP Toolkitを最初から内包しています。 HelloWorld.js var service = WScript.CreateObject("MSSOAP.SoapClient"); service.mssoapinit("http://localhost/WebService1/Service1.asmx?wsdl"); var result = service.HelloWorld(); WScript.Echo(result);
(余談)User-Agent 上記の方法でWSHからASP.NET WebサービスをコールしたときのHTTPログです。 WSDLリクエスト GET /WebService1/Service1.asmx?wsdl HTTP/1.1 Accept: */* Accept-Encoding: gzip, deflate User-Agent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; .NET CLR 1.0.3705; .NET CLR 1.1.4322) Host: localhost Connection: Keep-Alive WSDLレスポンス HTTP/1.1 200 OK Server: Microsoft-IIS/5.1 Date: Mon, 29 Dec 2003 17:08:21 GMT X-AspNet-Version: 1.1.4322 Cache-Control: private, max-age=0 Content-Type: text/xml; charset=utf-8 Content-Length: 2006 <?xml version="1.0" encoding="utf-8"?> <definitions xmlns:http="http://schemas.xmlsoap.org/wsdl/http/" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:s="http://www.w3.org/2001/XMLSchema" xmlns:s0="http://tempuri.org/" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/" xmlns:tm="http://microsoft.com/wsdl/mime/textMatching/" xmlns:mime="http://schemas.xmlsoap.org/wsdl/mime/" targetNamespace="http://tempuri.org/" xmlns="http://schemas.xmlsoap.org/wsdl/"> <types> <s:schema elementFormDefault="qualified" targetNamespace="http://tempuri.org/"> <s:element name="HelloWorld"> <s:complexType /> </s:element> <s:element name="HelloWorldResponse"> <s:complexType> <s:sequence> <s:element minOccurs="0" maxOccurs="1" name="HelloWorldResult" type="s:string" /> </s:sequence> </s:complexType> </s:element> </s:schema> </types> <message name="HelloWorldSoapIn"> <part name="parameters" element="s0:HelloWorld" /> </message> <message name="HelloWorldSoapOut"> <part name="parameters" element="s0:HelloWorldResponse" /> </message> <portType name="Service1Soap"> <operation name="HelloWorld"> <input message="s0:HelloWorldSoapIn" /> <output message="s0:HelloWorldSoapOut" /> </operation> </portType> <binding name="Service1Soap" type="s0:Service1Soap"> <soap:binding transport="http://schemas.xmlsoap.org/soap/http" style="document" /> <operation name="HelloWorld"> <soap:operation soapAction="http://tempuri.org/HelloWorld" style="document" /> <input> <soap:body use="literal" /> </input> <output> <soap:body use="literal" /> </output> </operation> </binding> <service name="Service1"> <port name="Service1Soap" binding="s0:Service1Soap"> <soap:address location="http://localhost/WebService1/Service1.asmx" /> </port> </service> </definitions> サービスリクエスト POST /WebService1/Service1.asmx HTTP/1.1 SOAPAction: "http://tempuri.org/HelloWorld" Content-Type: text/xml User-Agent: SOAP Sdk Host: localhost Content-Length: 224 Connection: Keep-Alive Cache-Control: no-cache <?xml version="1.0" encoding="UTF-8" standalone="no"?> <SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"> <SOAP-ENV:Body> <HelloWorld xmlns="http://tempuri.org/"/> </SOAP-ENV:Body> </SOAP-ENV:Envelope> サービスレスポンス HTTP/1.1 100 Continue Server: Microsoft-IIS/5.1 Date: Mon, 29 Dec 2003 17:08:21 GMT HTTP/1.1 200 OK Server: Microsoft-IIS/5.1 Date: Mon, 29 Dec 2003 17:08:21 GMT X-AspNet-Version: 1.1.4322 Cache-Control: private, max-age=0 Content-Type: text/xml; charset=utf-8 Content-Length: 376 <?xml version="1.0" encoding="utf-8"?> <soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"> <soap:Body> <HelloWorldResponse xmlns="http://tempuri.org/"> <HelloWorldResult>こんにちは、世界</HelloWorldResult> </HelloWorldResponse> </soap:Body> </soap:Envelope> ちなみに.NET WindowsアプリケーションからWebサービスをコールするときのUser-Agentは Mozilla/4.0 (compatible; MSIE 6.0; MS Web Services Client Protocol 1.1.4322.573) のようです。 |