SOAP: Difference between revisions

3,095 bytes added ,  6 years ago
Added C implementation.
(Added C implementation.)
Line 36:
#Include ws4ahk.ahk ; http://www.autohotkey.net/~easycom/ws4ahk_public_api.html</lang>
 
=={{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.
{{libheader|libcurl}}
<lang C>
/*Abhishek Ghosh, 26th October 2017*/
 
#include <curl/curl.h>
#include <string.h>
#include <stdio.h>
 
size_t write_data(void *ptr, size_t size, size_t nmeb, void *stream){
return fwrite(ptr,size,nmeb,stream);
}
 
size_t read_data(void *ptr, size_t size, size_t nmeb, void *stream){
return fread(ptr,size,nmeb,stream);
}
 
void callSOAP(char* URL, char * inFile, char * outFile) {
 
FILE * rfp = fopen(inFile, "r");
if(!rfp)
perror("Read File Open:");
 
FILE * wfp = fopen(outFile, "w+");
if(!wfp)
perror("Write File Open:");
 
struct curl_slist *header = 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:");
CURL *curl;
 
curl = curl_easy_init();
if(curl) {
curl_easy_setopt(curl, CURLOPT_URL, URL);
curl_easy_setopt(curl, CURLOPT_POST, 1L);
curl_easy_setopt(curl, CURLOPT_READFUNCTION, read_data);
curl_easy_setopt(curl, CURLOPT_READDATA, rfp);
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, write_data);
curl_easy_setopt(curl, CURLOPT_WRITEDATA, wfp);
curl_easy_setopt(curl, CURLOPT_HTTPHEADER, header);
curl_easy_setopt(curl, CURLOPT_POSTFIELDSIZE_LARGE, (curl_off_t)-1);
curl_easy_setopt(curl, CURLOPT_VERBOSE,1L);
curl_easy_perform(curl);
 
curl_easy_cleanup(curl);
}
}
 
int main(int argC,char* argV[])
{
if(argC!=4)
printf("Usage : %s <URL of WSDL> <Input file path> <Output File Path>",argV[0]);
else
callSOAP(argV[1],argV[2],argV[3]);
return 0;
}
</lang>
Input XML for soapFunc()
<lang XML>
<?xml version="1.0" encoding="UTF-8"?>
<soapenv:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:dom="http://example.com/soap/wsdl">
<soapenv:Header/>
<soapenv:Body>
<dom:soapFunc soapenv:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"/>
</soapenv:Body>
</soapenv:Envelope>
</lang>
Input XML for anotherSoapFunc()
<lang XML>
<?xml version="1.0" encoding="UTF-8"?>
<soapenv:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:dom="http://example.com/soap/wsdl">
<soapenv:Header/>
<soapenv:Body>
<dom:anotherSoapFunc soapenv:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"/>
</soapenv:Body>
</soapenv:Envelope>
</lang>
=={{header|ColdFusion}}==
<lang cfm><cfset client = createObject("webservice","http://example.com/soap/wsdl")>
<cfset result = client.soapFunc("hello")>
<cfset result = client.anotherSoapFunc(34234)></lang>
 
 
=={{header|F Sharp|F#}}==
503

edits