SOAP: Difference between revisions

2,569 bytes added ,  6 years ago
Added Kotlin
(Added C implementation.)
(Added Kotlin)
Line 171:
return "Goodbye" || s[1:-1]
end</lang>
 
=={{header|Kotlin}}==
{{trans|C}}
{{libheader|libcurl}}
{{works with|Ubuntu 14.04}}
Assuming that libcurl is already installed on your system in the default location(s), you first need to build libcurl.klib using the following .def file and the cinterop tool:
<pre>
// libcurl.def
headers = /usr/include/curl/curl.h
linkerOpts.linux = -L/usr/lib/x86_64-linux-gnu -lcurl
</pre>
Next, you need to compile the following Kotlin program, linking against libcurl.klib.
<lang scala>// Kotlin Native v0.6
 
import kotlinx.cinterop.*
import platform.posix.*
import libcurl.*
 
fun writeData(ptr: COpaquePointer?, size: size_t, nmeb: size_t, stream: COpaquePointer?)
= fwrite(ptr, size, nmeb, stream?.reinterpret<FILE>())
 
fun readData(ptr: COpaquePointer?, size: size_t, nmeb: size_t, stream: COpaquePointer?)
= fread(ptr, size, nmeb, stream?.reinterpret<FILE>())
 
fun callSOAP(url: String, inFile: String, outFile: String) {
val rfp = fopen(inFile, "r")
if (rfp == null) {
perror("Read File Open: ")
exit(1)
}
val wfp = fopen(outFile, "w+")
if (wfp == null) {
perror("Write File Open: ")
fclose(rfp)
exit(1)
}
 
var header: CPointer<curl_slist>? = null
header = curl_slist_append (header, "Content-Type:text/xml")
header = curl_slist_append (header, "SOAPAction: rsc")
header = curl_slist_append (header, "Transfer-Encoding: chunked")
header = curl_slist_append (header, "Expect:")
 
val curl = curl_easy_init()
if (curl != null) {
curl_easy_setopt(curl, CURLOPT_URL, url)
curl_easy_setopt(curl, CURLOPT_POST, 1L)
curl_easy_setopt(curl, CURLOPT_READFUNCTION, staticCFunction(::readData))
curl_easy_setopt(curl, CURLOPT_READDATA, rfp)
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, staticCFunction(::writeData))
curl_easy_setopt(curl, CURLOPT_WRITEDATA, wfp)
curl_easy_setopt(curl, CURLOPT_HTTPHEADER, header)
curl_easy_setopt(curl, CURLOPT_POSTFIELDSIZE_LARGE, -1L)
curl_easy_setopt(curl, CURLOPT_VERBOSE, 1L)
curl_easy_perform(curl)
curl_easy_cleanup(curl)
}
 
fclose(rfp)
fclose(wfp)
}
 
fun main(args: Array<String>) {
if (args.size != 3) {
println("You need to pass exactly 3 command line arguments, namely :-")
println(" <URL of WSDL> <Input file path> <Output File Path>")
return
}
callSOAP(args[0], args[1], args[2])
}</lang>
Finally, the resulting .kexe file should be executed passing it similar command line arguments to the C entry.
 
=={{header|Mathematica}}==
9,485

edits