Unicode C
Unicode C
HTTP SOAP 1.2 Request and Response using POST
See more HTTP Examples
Demonstrates a working SOAP 1.2 request and response using POST with a live server. You may try running this example with the URLs and data provided. See http://wsf.cdyne.com/WeatherWS/Weather.asmx?op=GetCityWeatherByZIP for details.Note: This example is correct in theory, but no longer works for live testing because the SOAP service provider (cdyne.com) has made changes or discontinued the free service.
Chilkat Unicode C Downloads
#include <C_CkHttpW.h>
#include <C_CkXmlW.h>
#include <C_CkHttpRequestW.h>
#include <C_CkHttpResponseW.h>
void ChilkatSample(void)
{
BOOL success;
HCkHttpW http;
HCkXmlW soapXml;
HCkHttpRequestW req;
HCkHttpResponseW resp;
HCkXmlW xmlResponse;
success = FALSE;
// This example requires the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.
// --------------------------------------------------------------------------------
// Also see Chilkat's Online WSDL Code Generator
// to generate code and SOAP Request and Response XML for each operation in a WSDL.
// --------------------------------------------------------------------------------
http = CkHttpW_Create();
soapXml = CkXmlW_Create();
CkXmlW_putTag(soapXml,L"soap12:Envelope");
success = CkXmlW_AddAttribute(soapXml,L"xmlns:xsi",L"http://www.w3.org/2001/XMLSchema-instance");
success = CkXmlW_AddAttribute(soapXml,L"xmlns:xsd",L"http://www.w3.org/2001/XMLSchema");
success = CkXmlW_AddAttribute(soapXml,L"xmlns:soap12",L"http://www.w3.org/2003/05/soap-envelope");
CkXmlW_NewChild2(soapXml,L"soap12:Body",L"");
success = CkXmlW_GetChild2(soapXml,0);
CkXmlW_NewChild2(soapXml,L"GetCityWeatherByZIP",L"");
success = CkXmlW_GetChild2(soapXml,0);
success = CkXmlW_AddAttribute(soapXml,L"xmlns",L"http://ws.cdyne.com/WeatherWS/");
CkXmlW_NewChild2(soapXml,L"ZIP",L"60187");
CkXmlW_GetRoot2(soapXml);
wprintf(L"%s\n",CkXmlW_getXml(soapXml));
req = CkHttpRequestW_Create();
CkHttpRequestW_putHttpVerb(req,L"POST");
CkHttpRequestW_putSendCharset(req,FALSE);
CkHttpRequestW_AddHeader(req,L"Content-Type",L"application/soap+xml; charset=utf-8");
CkHttpRequestW_AddHeader(req,L"SOAPAction",L"http://ws.cdyne.com/WeatherWS/GetCityWeatherByZIP");
CkHttpRequestW_putPath(req,L"/WeatherWS/Weather.asmx");
success = CkHttpRequestW_LoadBodyFromString(req,CkXmlW_getXml(soapXml),L"utf-8");
CkHttpW_putFollowRedirects(http,TRUE);
resp = CkHttpResponseW_Create();
success = CkHttpW_HttpSReq(http,L"wsf.cdyne.com",80,FALSE,req,resp);
if (success == FALSE) {
wprintf(L"%s\n",CkHttpW_lastErrorText(http));
CkHttpW_Dispose(http);
CkXmlW_Dispose(soapXml);
CkHttpRequestW_Dispose(req);
CkHttpResponseW_Dispose(resp);
return;
}
xmlResponse = CkXmlW_Create();
success = CkXmlW_LoadXml(xmlResponse,CkHttpResponseW_bodyStr(resp));
wprintf(L"%s\n",CkXmlW_getXml(xmlResponse));
CkHttpW_Dispose(http);
CkXmlW_Dispose(soapXml);
CkHttpRequestW_Dispose(req);
CkHttpResponseW_Dispose(resp);
CkXmlW_Dispose(xmlResponse);
}