SOAP: Difference between revisions
Content added Content deleted
m (→{{header|Diego}}: syntax) |
Thundergnat (talk | contribs) m (syntax highlighting fixup automation) |
||
Line 5: | Line 5: | ||
=={{header|ActionScript}}== |
=={{header|ActionScript}}== |
||
{{works with|ActionScript|3.0}} |
{{works with|ActionScript|3.0}} |
||
< |
<syntaxhighlight lang="actionscript">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 20: | ||
private function anotherSoapFunc_Result(event:ResultEvent):void { |
private function anotherSoapFunc_Result(event:ResultEvent):void { |
||
// do another something |
// do another something |
||
}</ |
}</syntaxhighlight> |
||
=={{header|AutoHotkey}}== |
=={{header|AutoHotkey}}== |
||
using embedded vb scripting. |
using embedded vb scripting. |
||
{{libheader|ws4ahk}} |
{{libheader|ws4ahk}} |
||
< |
<syntaxhighlight lang="autohotkey">WS_Initialize() |
||
WS_Exec("Set client = CreateObject(""MSSOAP.SoapClient"")") |
WS_Exec("Set client = CreateObject(""MSSOAP.SoapClient"")") |
||
WS_Exec("client.MSSoapInit ""http://example.com/soap/wsdl""") |
WS_Exec("client.MSSoapInit ""http://example.com/soap/wsdl""") |
||
Line 35: | Line 35: | ||
Msgbox % result . "`n" . result2 |
Msgbox % result . "`n" . result2 |
||
WS_Uninitialize() |
WS_Uninitialize() |
||
#Include ws4ahk.ahk ; http://www.autohotkey.net/~easycom/ws4ahk_public_api.html</ |
#Include ws4ahk.ahk ; http://www.autohotkey.net/~easycom/ws4ahk_public_api.html</syntaxhighlight> |
||
=={{header|C}}== |
=={{header|C}}== |
||
Although this is a generic task to show that calling SOAP functions are possible, the following implementation is geared for the real world. In order to execute it, just choose an actual WSDL URL and construct the input XML files for the functions properly, this can also be done in C but requires libraries like xerces unless you want to really construct the XML from scratch. |
Although this is a generic task to show that calling SOAP functions are possible, the following implementation is geared for the real world. In order to execute it, just choose an actual WSDL URL and construct the input XML files for the functions properly, this can also be done in C but requires libraries like xerces unless you want to really construct the XML from scratch. |
||
{{libheader|libcurl}} |
{{libheader|libcurl}} |
||
<syntaxhighlight lang="c"> |
|||
<lang C> |
|||
#include <curl/curl.h> |
#include <curl/curl.h> |
||
#include <string.h> |
#include <string.h> |
||
Line 95: | Line 95: | ||
return 0; |
return 0; |
||
} |
} |
||
</syntaxhighlight> |
|||
</lang> |
|||
Input XML for soapFunc() |
Input XML for soapFunc() |
||
<syntaxhighlight lang="xml"> |
|||
<lang XML> |
|||
<?xml version="1.0" encoding="UTF-8"?> |
<?xml version="1.0" encoding="UTF-8"?> |
||
<soapenv:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" |
<soapenv:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" |
||
Line 108: | Line 108: | ||
</soapenv:Body> |
</soapenv:Body> |
||
</soapenv:Envelope> |
</soapenv:Envelope> |
||
</syntaxhighlight> |
|||
</lang> |
|||
Input XML for anotherSoapFunc() |
Input XML for anotherSoapFunc() |
||
<syntaxhighlight lang="xml"> |
|||
<lang XML> |
|||
<?xml version="1.0" encoding="UTF-8"?> |
<?xml version="1.0" encoding="UTF-8"?> |
||
<soapenv:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" |
<soapenv:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" |
||
Line 121: | Line 121: | ||
</soapenv:Body> |
</soapenv:Body> |
||
</soapenv:Envelope> |
</soapenv:Envelope> |
||
</syntaxhighlight> |
|||
</lang> |
|||
=={{header|Clojure}}== |
=={{header|Clojure}}== |
||
< |
<syntaxhighlight lang="clojure">(require '[clj-soap.core :as soap]) |
||
(let [client (soap/client-fn "http://example.com/soap/wsdl")] |
(let [client (soap/client-fn "http://example.com/soap/wsdl")] |
||
(client :soapFunc) |
(client :soapFunc) |
||
(client :anotherSoapFunc))</ |
(client :anotherSoapFunc))</syntaxhighlight> |
||
=={{header|ColdFusion}}== |
=={{header|ColdFusion}}== |
||
< |
<syntaxhighlight 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)></ |
<cfset result = client.anotherSoapFunc(34234)></syntaxhighlight> |
||
=={{header|Diego}}== |
=={{header|Diego}}== |
||
< |
<syntaxhighlight lang="diego">apt_knowledge(webservices); // Commanding apt_protocol(SOAP); will also apt_knowledge(webservices); |
||
set_namespace(rosettacode); |
set_namespace(rosettacode); |
||
Line 144: | Line 144: | ||
me_msg()_invoke(ws)_anotherSoapFunc(32234); // alternative syntax |
me_msg()_invoke(ws)_anotherSoapFunc(32234); // alternative syntax |
||
reset_namespace();</ |
reset_namespace();</syntaxhighlight> |
||
=={{header|F Sharp|F#}}== |
=={{header|F Sharp|F#}}== |
||
The availability of functions and the type of parameters is checked at compile time. The development environment supports auto-completion and parameter information just like for regular types. |
The availability of functions and the type of parameters is checked at compile time. The development environment supports auto-completion and parameter information just like for regular types. |
||
< |
<syntaxhighlight lang="fsharp">open Microsoft.FSharp.Data.TypeProviders |
||
type Wsdl = WsdlService<"http://example.com/soap/wsdl"> |
type Wsdl = WsdlService<"http://example.com/soap/wsdl"> |
||
let result = Wsdl.soapFunc("hello") |
let result = Wsdl.soapFunc("hello") |
||
let result2 = Wsdl.anotherSoapFunc(34234)</ |
let result2 = Wsdl.anotherSoapFunc(34234)</syntaxhighlight> |
||
=={{header|Go}}== |
=={{header|Go}}== |
||
Line 159: | Line 159: | ||
<br> |
<br> |
||
To make this example a bit more interesting we test against a publicly available working SOAP server at the date of posting. |
To make this example a bit more interesting we test against a publicly available working SOAP server at the date of posting. |
||
< |
<syntaxhighlight lang="go">package main |
||
import ( |
import ( |
||
Line 211: | Line 211: | ||
fmt.Println("Name : ", rv.Name) |
fmt.Println("Name : ", rv.Name) |
||
fmt.Println("Address : ", rv.Address) |
fmt.Println("Address : ", rv.Address) |
||
}</ |
}</syntaxhighlight> |
||
{{out}} |
{{out}} |
||
Line 227: | Line 227: | ||
This code uses Unicon features not available in Icon. |
This code uses Unicon features not available in Icon. |
||
< |
<syntaxhighlight lang="unicon">import soap |
||
procedure main(A) |
procedure main(A) |
||
Line 233: | Line 233: | ||
write("soapFunc: ",soap.call("soapFunc")) |
write("soapFunc: ",soap.call("soapFunc")) |
||
write("anotherSoapFunc: ",soap.call("anotherSoapFunc")) |
write("anotherSoapFunc: ",soap.call("anotherSoapFunc")) |
||
end</ |
end</syntaxhighlight> |
||
A matching SOAP server can be implemented as: |
A matching SOAP server can be implemented as: |
||
< |
<syntaxhighlight lang="unicon">import soap |
||
procedure main() |
procedure main() |
||
Line 256: | Line 256: | ||
every (s := " ") ||:= (!A || " ") |
every (s := " ") ||:= (!A || " ") |
||
return "Goodbye" || s[1:-1] |
return "Goodbye" || s[1:-1] |
||
end</ |
end</syntaxhighlight> |
||
=={{header|Julia}}== |
=={{header|Julia}}== |
||
{{trans|C}} |
{{trans|C}} |
||
< |
<syntaxhighlight lang="julia">using LibCURL |
||
function callSOAP(url, infilename, outfilename) |
function callSOAP(url, infilename, outfilename) |
||
Line 291: | Line 291: | ||
println("Usage : $(@__FILE__) <URL of WSDL> <Input file path> <Output File Path>") |
println("Usage : $(@__FILE__) <URL of WSDL> <Input file path> <Output File Path>") |
||
end |
end |
||
</syntaxhighlight> |
|||
</lang> |
|||
=={{header|Kotlin}}== |
=={{header|Kotlin}}== |
||
Line 304: | Line 304: | ||
</pre> |
</pre> |
||
Next, you need to compile the following Kotlin program, linking against libcurl.klib. |
Next, you need to compile the following Kotlin program, linking against libcurl.klib. |
||
< |
<syntaxhighlight lang="scala">// Kotlin Native v0.6 |
||
import kotlinx.cinterop.* |
import kotlinx.cinterop.* |
||
Line 362: | Line 362: | ||
} |
} |
||
callSOAP(args[0], args[1], args[2]) |
callSOAP(args[0], args[1], args[2]) |
||
}</ |
}</syntaxhighlight> |
||
Finally, the resulting .kexe file should be executed passing it similar command line arguments to the C entry. |
Finally, the resulting .kexe file should be executed passing it similar command line arguments to the C entry. |
||
=={{header|Mathematica}}/{{header|Wolfram Language}}== |
=={{header|Mathematica}}/{{header|Wolfram Language}}== |
||
< |
<syntaxhighlight lang="mathematica">InstallService["http://example.com/soap/wsdl"]; |
||
soapFunc["Hello"]; |
soapFunc["Hello"]; |
||
anotherSoapFunc[12345];</ |
anotherSoapFunc[12345];</syntaxhighlight> |
||
=={{header|Perl}}== |
=={{header|Perl}}== |
||
{{libheader|SOAP::Lite}} |
{{libheader|SOAP::Lite}} |
||
< |
<syntaxhighlight lang="perl">use SOAP::Lite; |
||
print SOAP::Lite |
print SOAP::Lite |
||
Line 379: | Line 379: | ||
print SOAP::Lite |
print SOAP::Lite |
||
-> service('http://example.com/soap/wsdl') |
-> service('http://example.com/soap/wsdl') |
||
-> anotherSoapFunc(34234);</ |
-> anotherSoapFunc(34234);</syntaxhighlight> |
||
=={{header|Phix}}== |
=={{header|Phix}}== |
||
{{libheader|Phix/libcurl}} |
{{libheader|Phix/libcurl}} |
||
<!--< |
<!--<syntaxhighlight lang="phix">(notonline)--> |
||
<span style="color: #000080;font-style:italic;">-- |
<span style="color: #000080;font-style:italic;">-- |
||
-- demo\rosetta\SOAP.exw |
-- demo\rosetta\SOAP.exw |
||
Line 440: | Line 440: | ||
<span style="color: #7060A8;">curl_easy_cleanup</span><span style="color: #0000FF;">(</span><span style="color: #000000;">curl</span><span style="color: #0000FF;">)</span> |
<span style="color: #7060A8;">curl_easy_cleanup</span><span style="color: #0000FF;">(</span><span style="color: #000000;">curl</span><span style="color: #0000FF;">)</span> |
||
<span style="color: #7060A8;">curl_global_cleanup</span><span style="color: #0000FF;">()</span> |
<span style="color: #7060A8;">curl_global_cleanup</span><span style="color: #0000FF;">()</span> |
||
<!--</ |
<!--</syntaxhighlight>--> |
||
{{out}} |
{{out}} |
||
note: foo/bar/baz are shown properly escaped on the terminal. |
note: foo/bar/baz are shown properly escaped on the terminal. |
||
Line 481: | Line 481: | ||
=={{header|PHP}}== |
=={{header|PHP}}== |
||
{{works with|PHP|5.0.0+}} |
{{works with|PHP|5.0.0+}} |
||
< |
<syntaxhighlight 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"); |
||
Line 494: | Line 494: | ||
//list if SOAP Functions |
//list if SOAP Functions |
||
print_r($client->__getFunctions()); |
print_r($client->__getFunctions()); |
||
?></ |
?></syntaxhighlight> |
||
=={{header|PureBasic}}== |
=={{header|PureBasic}}== |
||
<syntaxhighlight lang="purebasic"> |
|||
<lang Purebasic> |
|||
XIncludeFile "COMatePLUS.pbi" |
XIncludeFile "COMatePLUS.pbi" |
||
Define.COMateObject soapObject = COMate_CreateObject("MSSOAP.SoapClient") |
Define.COMateObject soapObject = COMate_CreateObject("MSSOAP.SoapClient") |
||
Line 503: | Line 503: | ||
result = soapObject\Invoke("soapFunc('hello')") |
result = soapObject\Invoke("soapFunc('hello')") |
||
result2 = soapObject\Invoke("anotherSoapFunc(34234)") |
result2 = soapObject\Invoke("anotherSoapFunc(34234)") |
||
</syntaxhighlight> |
|||
</lang> |
|||
=={{header|Python}}== |
=={{header|Python}}== |
||
{{works with|Python|2.4 and 2.5}} |
{{works with|Python|2.4 and 2.5}} |
||
< |
<syntaxhighlight 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)</ |
result = proxy.anotherSoapFunc(34234)</syntaxhighlight> |
||
'''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 516: | Line 516: | ||
=={{header|Raku}}== |
=={{header|Raku}}== |
||
(formerly Perl 6) |
(formerly Perl 6) |
||
<lang |
<syntaxhighlight lang="raku" line># Reference: |
||
# https://github.com/retupmoca/P6-SOAP |
# https://github.com/retupmoca/P6-SOAP |
||
# http://wiki.dreamfactory.com/DreamFactory/Tutorials/Temp_Conversion_SOAP_API |
# http://wiki.dreamfactory.com/DreamFactory/Tutorials/Temp_Conversion_SOAP_API |
||
Line 527: | Line 527: | ||
say $request.call('CelsiusToFahrenheit', Celsius => 100 ) or die; |
say $request.call('CelsiusToFahrenheit', Celsius => 100 ) or die; |
||
say $request.call('FahrenheitToCelsius', Fahrenheit => 212 ) or die;</ |
say $request.call('FahrenheitToCelsius', Fahrenheit => 212 ) or die;</syntaxhighlight> |
||
{{out}} |
{{out}} |
||
<pre>{CelsiusToFahrenheitResult => [212]} |
<pre>{CelsiusToFahrenheitResult => [212]} |
||
Line 535: | Line 535: | ||
=={{header|Ruby}}== |
=={{header|Ruby}}== |
||
{{works with|Ruby|1.8}} |
{{works with|Ruby|1.8}} |
||
< |
<syntaxhighlight lang="ruby">require 'soap/wsdlDriver' |
||
wsdl = SOAP::WSDLDriverFactory.new("http://example.com/soap/wsdl") |
wsdl = SOAP::WSDLDriverFactory.new("http://example.com/soap/wsdl") |
||
Line 544: | Line 544: | ||
response2 = soap.anotherSoapFunc(:aNumber => 42) |
response2 = soap.anotherSoapFunc(:aNumber => 42) |
||
puts response2.anotherSoapFuncReturn</ |
puts response2.anotherSoapFuncReturn</syntaxhighlight> |
||
=={{header|Smalltalk}}== |
=={{header|Smalltalk}}== |
||
{{works with|Smalltalk/X}} {{works with|Dolphin Smalltalk}} (not sure about Pharo and VW) |
{{works with|Smalltalk/X}} {{works with|Dolphin Smalltalk}} (not sure about Pharo and VW) |
||
(assuming that the open source [http://www.mars.dti.ne.jp/~umejava/smalltalk/soapOpera/index.html SOAPSpray] package has been loaded.) |
(assuming that the open source [http://www.mars.dti.ne.jp/~umejava/smalltalk/soapOpera/index.html SOAPSpray] package has been loaded.) |
||
< |
<syntaxhighlight lang="smalltalk">| service client response1 response2 | |
||
service := SprayWSDLService onUrl: 'http://example.com/soap/wsdl'. |
service := SprayWSDLService onUrl: 'http://example.com/soap/wsdl'. |
||
Line 555: | Line 555: | ||
client := service createClient. |
client := service createClient. |
||
response1 := client send: 'soapFunc' withArguments:{ 'hello' }. |
response1 := client send: 'soapFunc' withArguments:{ 'hello' }. |
||
response2 := client send: 'anotherSoapFunc' withArguments:{ 34234 }.</ |
response2 := client send: 'anotherSoapFunc' withArguments:{ 34234 }.</syntaxhighlight> |
||
=={{header|Tcl}}== |
=={{header|Tcl}}== |
||
{{works with|Tcl|8.5+}} |
{{works with|Tcl|8.5+}} |
||
Uses the <code>[http://code.google.com/p/tclws/ tclws]</code> package. |
Uses the <code>[http://code.google.com/p/tclws/ tclws]</code> package. |
||
< |
<syntaxhighlight lang="tcl">package require WS::Client |
||
# Grok the service, and generate stubs |
# Grok the service, and generate stubs |
||
Line 568: | Line 568: | ||
# Do the calls |
# Do the calls |
||
set result1 [ExampleService::soapFunc "hello"] |
set result1 [ExampleService::soapFunc "hello"] |
||
set result2 [ExampleService::anotherSoapFunc 34234]</ |
set result2 [ExampleService::anotherSoapFunc 34234]</syntaxhighlight> |
||
=={{header|Uniface}}== |
=={{header|Uniface}}== |
||
Assuming http://example.com/soap/wsdl has been imported into repository and, as result, exists a new component called "webservice" |
Assuming http://example.com/soap/wsdl has been imported into repository and, as result, exists a new component called "webservice" |
||
<syntaxhighlight lang="uniface"> |
|||
<lang Uniface> |
|||
variables |
variables |
||
string result1, result2 |
string result1, result2 |
||
Line 580: | Line 580: | ||
activate "webservice".soapFunc("hello", result1) |
activate "webservice".soapFunc("hello", result1) |
||
activate "webservice".anotherSoapFunc(34234, result2) |
activate "webservice".anotherSoapFunc(34234, result2) |
||
</syntaxhighlight> |
|||
</lang> |
|||
=={{header|VBScript}}== |
=={{header|VBScript}}== |
||
< |
<syntaxhighlight 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)</ |
result = client.anotherSoapFunc(34234)</syntaxhighlight> |
||
=={{header|Visual Objects}}== |
=={{header|Visual Objects}}== |
||
< |
<syntaxhighlight lang="visobj">LOCAL oSoapClient AS OBJECT //OLEAUTOOBJECT |
||
LOCAL cUrl AS STRING |
LOCAL cUrl AS STRING |
||
LOCAL uResult AS USUAL |
LOCAL uResult AS USUAL |
||
Line 602: | Line 602: | ||
uResult := oSoapClient:soapFunc("hello") |
uResult := oSoapClient:soapFunc("hello") |
||
uResult := oSoapClient:anotherSoapFunc(34234) |
uResult := oSoapClient:anotherSoapFunc(34234) |
||
ENDIF</ |
ENDIF</syntaxhighlight> |
||
=={{header|Wren}}== |
=={{header|Wren}}== |
||
Line 608: | Line 608: | ||
{{libheader|libcurl}} |
{{libheader|libcurl}} |
||
An embedded program so we can ask the C host to communicate with libcurl for us. |
An embedded program so we can ask the C host to communicate with libcurl for us. |
||
< |
<syntaxhighlight lang="ecmascript">/* soap.wren */ |
||
var CURLOPT_URL = 10002 |
var CURLOPT_URL = 10002 |
||
Line 674: | Line 674: | ||
} |
} |
||
soap.call(File.url, File.readFile, File.writeFile)</ |
soap.call(File.url, File.readFile, File.writeFile)</syntaxhighlight> |
||
<br> |
<br> |
||
We now embed this in the following C program, compile and run it. |
We now embed this in the following C program, compile and run it. |
||
< |
<syntaxhighlight lang="c">#include <stdio.h> |
||
#include <stdlib.h> |
#include <stdlib.h> |
||
#include <string.h> |
#include <string.h> |
||
Line 868: | Line 868: | ||
free(script); |
free(script); |
||
return 0; |
return 0; |
||
}</ |
}</syntaxhighlight> |
||
{{omit from|Batch File|Does not have network access.}} |
{{omit from|Batch File|Does not have network access.}} |