SOAP: Difference between revisions
m Retro: omit |
No edit summary |
||
Line 179: | Line 179: | ||
{{omit from|Brainf***}} |
{{omit from|Brainf***}} |
||
{{omit from|M4}} |
{{omit from|M4}} |
||
{{omit from|Maxima}} |
|||
{{omit from|PARI/GP}} |
{{omit from|PARI/GP}} |
||
{{omit from|PostScript}} |
{{omit from|PostScript}} |
Revision as of 14:32, 12 June 2012
![Task](http://static.miraheze.org/rosettacodewiki/thumb/b/ba/Rcode-button-task-crushed.png/64px-Rcode-button-task-crushed.png)
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>
AutoHotkey
using embedded vb scripting.
<lang AutoHotkey>WS_Initialize()
WS_Exec("Set client = CreateObject(""MSSOAP.SoapClient"")") WS_Exec("client.MSSoapInit ""http://example.com/soap/wsdl""") callhello = client.soapFunc("hello") callanother = client.anotherSoapFunc(34234) WS_Eval(result, callhello) WS_Eval(result2, callanother) Msgbox % result . "`n" . result2 WS_Uninitialize()
- Include ws4ahk.ahk ; http://www.autohotkey.net/~easycom/ws4ahk_public_api.html</lang>
ColdFusion
<lang cfm><cfset client = createObject("webservice","http://example.com/soap/wsdl")> <cfset result = client.soapFunc("hello")> <cfset result = client.anotherSoapFunc(34234)></lang>
Icon and Unicon
provides the Soap package.
This code uses Unicon features not available in Icon. <lang unicon>import soap
procedure main(A)
soap := SoapClient(A[1] | "http://example.com/soap/wsdl") # Allow override of default write("soapFunc: ",soap.call("soapFunc")) write("anotherSoapFunc: ",soap.call("anotherSoapFunc"))
end</lang>
A matching SOAP server can be implemented as:
<lang unicon>import soap
procedure main()
server := SoapServer("http://example.com/soap/wsdl") server.addService("soapFunc", soapFunc) server.addService("anotherSoapFunc", anotherSoapFunc) msg := server.handleRequest() write(msg) exit(0)
end
procedure soapFunc(A[])
every (s := " ") ||:= (!A || " ") return "Hello" || s[1:-1]
end
procedure anotherSoapFunc(A[])
every (s := " ") ||:= (!A || " ") return "Goodbye" || s[1:-1]
end</lang>
Mathematica
<lang Mathematica>InstallService["http://example.com/soap/wsdl"]; soapFunc["Hello"]; anotherSoapFunc[12345]; </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>
PureBasic
<lang Purebasic> XIncludeFile "COMatePLUS.pbi" Define.COMateObject soapObject = COMate_CreateObject("MSSOAP.SoapClient") soapObject\Invoke("MSSoapInit('http://example.com/soap/wsdl')") result = soapObject\Invoke("soapFunc('hello')") result2 = soapObject\Invoke("anotherSoapFunc(34234)") </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
Ruby
<lang ruby>require 'soap/wsdlDriver'
wsdl = SOAP::WSDLDriverFactory.new("http://example.com/soap/wsdl") soap = wsdl.create_rpc_driver
response1 = soap.soapFunc(:elementName => "value") puts response1.soapFuncReturn
response2 = soap.anotherSoapFunc(:aNumber => 42) puts response2.anotherSoapFuncReturn</lang>
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 visobj>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>
- Less Than 10 Examples
- Programming Tasks
- Networking and Web Interaction
- Clarify task
- ActionScript
- AutoHotkey
- Ws4ahk
- ColdFusion
- Unicon
- Unicon Code Library
- Mathematica
- Perl
- PHP
- PureBasic
- Python
- Ruby
- Tcl
- VBScript
- Visual Objects
- Batch File/Omit
- Brainf***/Omit
- M4/Omit
- Maxima/Omit
- PARI/GP/Omit
- PostScript/Omit
- Retro/Omit
- TI-83 BASIC/Omit
- TI-89 BASIC/Omit
- Unlambda/Omit
- Yorick/Omit
- ZX Spectrum Basic/Omit