SOAP: Difference between revisions

From Rosetta Code
Content added Content deleted
(omit m4)
m (Fixed lang tags.)
Line 4: Line 4:
=={{header|ActionScript}}==
=={{header|ActionScript}}==
{{works with|ActionScript|3.0}}
{{works with|ActionScript|3.0}}
<lang actionscript>
<lang actionscript>import mx.rpc.soap.WebService;
import mx.rpc.soap.WebService;
import mx.rpc.events.ResultEvent;
import mx.rpc.events.ResultEvent;
var ws:WebService = new WebService();
var ws:WebService = new WebService();
Line 20: Line 19:
private function anotherSoapFunc_Result(event:ResultEvent):void {
private function anotherSoapFunc_Result(event:ResultEvent):void {
// do another something
// do another something
}</lang>
}
</lang>
=={{header|AutoHotkey}}==
=={{header|AutoHotkey}}==
using embedded vb scripting.
using embedded vb scripting.
Line 37: Line 35:


=={{header|ColdFusion}}==
=={{header|ColdFusion}}==
<lang cfm> <cfset client = createObject("webservice","http://example.com/soap/wsdl")>
<lang cfm><cfset client = createObject("webservice","http://example.com/soap/wsdl")>
<cfset result = client.soapFunc("hello")>
<cfset result = client.soapFunc("hello")>
<cfset result = client.anotherSoapFunc(34234)></lang>
<cfset result = client.anotherSoapFunc(34234)></lang>


=={{header|Perl}}==
=={{header|Perl}}==
{{libheader|SOAP::Lite}}
{{libheader|SOAP::Lite}}
<lang perl> use SOAP::Lite;
<lang perl>use SOAP::Lite;

print SOAP::Lite
print SOAP::Lite
-> service('http://example.com/soap/wsdl')
-> service('http://example.com/soap/wsdl')
-> soapFunc("hello");
-> soapFunc("hello");
print SOAP::Lite
print SOAP::Lite
-> service('http://example.com/soap/wsdl')
-> service('http://example.com/soap/wsdl')
-> anotherSoapFunc(34234);</lang>
-> anotherSoapFunc(34234);</lang>


=={{header|PHP}}==
=={{header|PHP}}==
{{works with|PHP|5.0.0+}}
{{works with|PHP|5.0.0+}}
<lang php> <?php
<lang php><?php
//load the wsdl file
//load the wsdl file
$client = new SoapClient("http://example.com/soap/definition.wsdl");
$client = new SoapClient("http://example.com/soap/definition.wsdl");
//functions are now available to be called
//functions are now available to be called
$result = $client->soapFunc("hello");
$result = $client->soapFunc("hello");
$result = $client->anotherSoapFunc(34234);
$result = $client->anotherSoapFunc(34234);


//SOAP Information
//SOAP Information
$client = new SoapClient("http://example.com/soap/definition.wsdl");
$client = new SoapClient("http://example.com/soap/definition.wsdl");
//list of SOAP types
//list of SOAP types
print_r($client->__getTypes());
print_r($client->__getTypes());
//list if SOAP Functions
//list if SOAP Functions
print_r($client->__getFunctions());
print_r($client->__getFunctions());
?></lang>
?></lang>


=={{header|Python}}==
=={{header|Python}}==
{{works with|Python|2.4 and 2.5}}
{{works with|Python|2.4 and 2.5}}
<lang python> from SOAPpy import WSDL
<lang python>from SOAPpy import WSDL
proxy = WSDL.Proxy("http://example.com/soap/wsdl")
proxy = WSDL.Proxy("http://example.com/soap/wsdl")
result = proxy.soapFunc("hello")
result = proxy.soapFunc("hello")
result = proxy.anotherSoapFunc(34234)</lang>
result = proxy.anotherSoapFunc(34234)</lang>


'''Note:''' SOAPpy is a third-party module and can be found at [http://pywebsvcs.sourceforge.net/ Python Web Services]
'''Note:''' SOAPpy is a third-party module and can be found at [http://pywebsvcs.sourceforge.net/ Python Web Services]
Line 105: Line 103:
=={{header|VBScript}}==
=={{header|VBScript}}==


<lang vbscript> Dim client
<lang vbscript>Dim client
Dim result
Dim result
Set client = CreateObject("MSSOAP.SoapClient")
Set client = CreateObject("MSSOAP.SoapClient")
client.MSSoapInit "http://example.com/soap/wsdl"
client.MSSoapInit "http://example.com/soap/wsdl"
result = client.soapFunc("hello")
result = client.soapFunc("hello")
result = client.anotherSoapFunc(34234)</lang>
result = client.anotherSoapFunc(34234)</lang>


=={{header|Visual Objects}}==
=={{header|Visual Objects}}==


<lang vobjects> LOCAL oSoapClient AS OLEAUTOOBJECT
<lang visobj>LOCAL oSoapClient AS OLEAUTOOBJECT
LOCAL cUrl AS STRING
LOCAL cUrl AS STRING
LOCAL uResult AS USUAL
LOCAL uResult AS USUAL
oSoapClient := OLEAutoObject{"MSSOAP.SoapClient30"}
oSoapClient := OLEAutoObject{"MSSOAP.SoapClient30"}
cUrl := "http://example.com/soap/wsdl"
cUrl := "http://example.com/soap/wsdl"
IF oSoapClient:fInit
IF oSoapClient:fInit
oSoapClient:mssoapinit(cUrl,"", "", "" )
oSoapClient:mssoapinit(cUrl,"", "", "" )
uResult := oSoapClient:soapFunc("hello")
uResult := oSoapClient:soapFunc("hello")
uResult := oSoapClient:anotherSoapFunc(34234)
uResult := oSoapClient:anotherSoapFunc(34234)
ENDIF</lang>
ENDIF</lang>


{{omit from|TI-83 BASIC}} {{omit from|TI-89 BASIC}} <!-- Does not have network access. -->
{{omit from|TI-83 BASIC}} {{omit from|TI-89 BASIC}} <!-- Does not have network access. -->

Revision as of 20:37, 19 November 2009

Task
SOAP
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( ).

This task has been flagged for clarification. Code on this page in its current state may be flagged incorrect once this task has been clarified. See this page's Talk page for discussion.


ActionScript

Works with: ActionScript version 3.0

<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.

Library: ws4ahk

<lang AutoHotkey>WS_Initialize()

   WS_Exec("Set client = CreateObject(""MSSOAP.SoapClient"")")
   callhello = client.soapFunc("hello")
   callanother = client.anotherSoapFunc(34234)
   
   WS_Eval(result, callhello)
   WS_Eval(result2, callanother)
   Msgbox % result . "`n" . result2
   WS_Uninitialize()
  1. 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>

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

Works with: PHP version 5.0.0+

<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

Works with: Python version 2.4 and 2.5

<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

Works with: Tcl version 8.5+

Uses the tclws package. <lang Tcl>package require WS::Client

  1. Grok the service, and generate stubs
WS::Client::GetAndParseWsdl http://example.com/soap/wsdl
WS::Client::CreateStubs ExampleService  ;# Assume that's the service name...
  1. 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>