SOAP: Difference between revisions
(→Tcl: Added implementation) |
(→Tcl: Correct to actually perform the official task: oops!) |
||
Line 69: | Line 69: | ||
<lang Tcl>package require WS::Client |
<lang Tcl>package require WS::Client |
||
# Grok the service |
# Grok the service, and generate stubs |
||
::WS::Client::GetAndParseWsdl http:// |
::WS::Client::GetAndParseWsdl http://example.com/soap/wsdl |
||
::WS::Client::CreateStubs ExampleService ;# Assume that's the service name... |
|||
# |
# Do the calls |
||
set result1 [ExampleService::soapFunc "hello"] |
|||
dict set args key "<your google license key here>" |
|||
set result2 [ExampleService::anotherSoapFunc 34234]</lang> |
|||
dict set args q {site:tclscripting.com font} |
|||
dict set args start 0 |
|||
dict set args maxResults 10 |
|||
dict set args filter true |
|||
dict set args restrict {} |
|||
dict set args safeSearch false |
|||
dict set args lr {} |
|||
dict set args ie latin1 |
|||
dict set args oe latin1 |
|||
# Do the call using the direct synchronous interface |
|||
set result [::WS::Client::DoCall GoogleSearchService doGoogleSearch $args] |
|||
# Print the results |
|||
foreach item [dict get $result return resultElements item] { |
|||
puts [dict get $item title] |
|||
puts [dict get $item URL] |
|||
puts "" |
|||
}</lang> |
|||
=={{header|VBScript}}== |
=={{header|VBScript}}== |
Revision as of 17:56, 9 May 2009
You are encouraged to solve this task according to the task description, using any language you may know.
In this task, the goal is to create a SOAP client which accesses functions defined at http://example.com/soap/wsdl, and calls the functions soapFunc( ) and anotherSoapFunc( ).
ActionScript
<lang actionscript> import mx.rpc.soap.WebService; import mx.rpc.events.ResultEvent; var ws:WebService = new WebService(); ws.wsdl = 'http://example.com/soap/wsdl'; ws.soapFunc.addEventListener("result",soapFunc_Result); ws.anotherSoapFunc.addEventListener("result",anotherSoapFunc_Result); ws.loadWSDL(); ws.soapFunc(); ws.anotherSoapFunc(); // method invocation callback handlers private function soapFunc_Result(event:ResultEvent):void {
// do something
} private function anotherSoapFunc_Result(event:ResultEvent):void {
// do another something
} </lang>
ColdFusion
<lang cfm> <cfset client = createObject("webservice","http://example.com/soap/wsdl")>
<cfset result = client.soapFunc("hello")> <cfset result = client.anotherSoapFunc(34234)></lang>
Perl
<lang perl> use SOAP::Lite;
print SOAP::Lite -> service('http://example.com/soap/wsdl') -> soapFunc("hello"); print SOAP::Lite -> service('http://example.com/soap/wsdl') -> anotherSoapFunc(34234);</lang>
PHP
<lang php> <?php
//load the wsdl file $client = new SoapClient("http://example.com/soap/definition.wsdl"); //functions are now available to be called $result = $client->soapFunc("hello"); $result = $client->anotherSoapFunc(34234);
//SOAP Information $client = new SoapClient("http://example.com/soap/definition.wsdl"); //list of SOAP types print_r($client->__getTypes()); //list if SOAP Functions print_r($client->__getFunctions()); ?></lang>
Python
<lang python> from SOAPpy import WSDL
proxy = WSDL.Proxy("http://example.com/soap/wsdl") result = proxy.soapFunc("hello") result = proxy.anotherSoapFunc(34234)</lang>
Note: SOAPpy is a third-party module and can be found at Python Web Services
Tcl
Uses the tclws
package.
<lang Tcl>package require WS::Client
- Grok the service, and generate stubs
- WS::Client::GetAndParseWsdl http://example.com/soap/wsdl
- WS::Client::CreateStubs ExampleService ;# Assume that's the service name...
- Do the calls
set result1 [ExampleService::soapFunc "hello"] set result2 [ExampleService::anotherSoapFunc 34234]</lang>
VBScript
<lang vbscript> Dim client
Dim result Set client = CreateObject("MSSOAP.SoapClient") client.MSSoapInit "http://example.com/soap/wsdl" result = client.soapFunc("hello") result = client.anotherSoapFunc(34234)</lang>
Visual Objects
<lang vobjects> LOCAL oSoapClient AS OLEAUTOOBJECT
LOCAL cUrl AS STRING LOCAL uResult AS USUAL oSoapClient := OLEAutoObject{"MSSOAP.SoapClient30"} cUrl := "http://example.com/soap/wsdl" IF oSoapClient:fInit oSoapClient:mssoapinit(cUrl,"", "", "" ) uResult := oSoapClient:soapFunc("hello") uResult := oSoapClient:anotherSoapFunc(34234) ENDIF</lang>