Chilkat HOME .NET Core C# Android™ AutoIt C C# C++ Chilkat2-Python CkPython Classic ASP DataFlex Delphi ActiveX Delphi DLL Go Java Lianja Mono C# Node.js Objective-C PHP ActiveX PHP Extension Perl PowerBuilder PowerShell PureBasic Ruby SQL Server Swift 2 Swift 3,4,5... Tcl Unicode C Unicode C++ VB.NET VBScript Visual Basic 6.0 Visual FoxPro Xojo Plugin
(Unicode C) HTTP SOAP 1.2 Request and Response using POSTDemonstrates 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.
#include <C_CkHttpW.h> #include <C_CkXmlW.h> #include <C_CkHttpRequestW.h> #include <C_CkHttpResponseW.h> void ChilkatSample(void) { HCkHttpW http; HCkXmlW soapXml; BOOL success; HCkHttpRequestW req; HCkHttpResponseW resp; HCkXmlW xmlResponse; // 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 = CkHttpW_SynchronousRequest(http,L"wsf.cdyne.com",80,FALSE,req); if (CkHttpW_getLastMethodSuccess(http) == FALSE) { wprintf(L"%s\n",CkHttpW_lastErrorText(http)); } else { xmlResponse = CkXmlW_Create(); success = CkXmlW_LoadXml(xmlResponse,CkHttpResponseW_bodyStr(resp)); wprintf(L"%s\n",CkXmlW_getXml(xmlResponse)); CkHttpResponseW_Dispose(resp); } CkHttpW_Dispose(http); CkXmlW_Dispose(soapXml); CkHttpRequestW_Dispose(req); CkXmlW_Dispose(xmlResponse); } |
© 2000-2024 Chilkat Software, Inc. All Rights Reserved.