Chilkat HOME ASP Visual Basic VB.NET C# Visual C++ C MFC Delphi FoxPro Java Perl PHP Python Ruby SQL Server VBScript
SOAP ExampleHow to send a SOAP request and get the XML response.
#include <C_CkHttpRequest.h> #include <C_CkHttp.h> #include <C_CkXml.h> #include <C_CkHttpResponse.h> void ChilkatSample(void) { HCkHttpRequest req; HCkHttp http; BOOL success; HCkXml soapReq; const char * domain; long port; BOOL ssl; HCkHttpResponse resp; HCkXml soapResp; HCkXml xmlResp; req = CkHttpRequest_Create(); http = CkHttp_Create(); // Any string unlocks the component for the 1st 30-days. success = CkHttp_UnlockComponent(http,"Anything for 30-day trial"); if (success != TRUE) { printf("%s\n",CkHttp_lastErrorText(http)); return; } // Build this XML SOAP request: // <?xml version="1.0" encoding="utf-8"?> // <soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" // xmlns:xsd="http://www.w3.org/2001/XMLSchema" // xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"> // <soap:Body> // <GetQuote xmlns="http://www.webserviceX.NET/"> // <symbol>string</symbol> // </GetQuote> // </soap:Body> // </soap:Envelope> soapReq = CkXml_Create(); CkXml_putEncoding(soapReq,"utf-8"); CkXml_putTag(soapReq,"soap:Envelope"); CkXml_AddAttribute(soapReq,"xmlns:xsi","http://www.w3.org/2001/XMLSchema-instance"); CkXml_AddAttribute(soapReq,"xmlns:xsd","http://www.w3.org/2001/XMLSchema"); CkXml_AddAttribute(soapReq,"xmlns:soap","http://schemas.xmlsoap.org/soap/envelope/"); CkXml_NewChild2(soapReq,"soap:Body",""); CkXml_FirstChild2(soapReq); CkXml_NewChild2(soapReq,"GetQuote",""); CkXml_FirstChild2(soapReq); CkXml_AddAttribute(soapReq,"xmlns","http://www.webserviceX.NET/"); CkXml_NewChild2(soapReq,"symbol","MSFT"); CkXml_GetRoot2(soapReq); printf("%s\n",CkXml_getXml(soapReq)); // Build an SOAP request. CkHttpRequest_UseXmlHttp(req,CkXml_getXml(soapReq)); CkHttpRequest_putPath(req,"/stockquote.asmx"); CkHttpRequest_AddHeader(req,"SOAPAction","http://www.webserviceX.NET/GetQuote"); // Send the HTTP POST and get the response. Note: This is a blocking call. // The method does not return until the full HTTP response is received. domain = "www.webservicex.net"; port = 80; ssl = FALSE; resp = CkHttp_SynchronousRequest(http,domain,port,ssl,req); if (resp == 0 ) { printf("%s\n",CkHttp_lastErrorText(http)); } else { // The XML response is in the BodyStr property of the response object: soapResp = CkXml_Create(); CkXml_LoadXml(soapResp,CkHttpResponse_bodyStr(resp)); // The response will look like this: // <?xml version="1.0" encoding="utf-8"?> // <soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" // xmlns:xsd="http://www.w3.org/2001/XMLSchema" // xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"> // <soap:Body> // <GetQuoteResponse xmlns="http://www.webserviceX.NET/"> // <GetQuoteResult>string</GetQuoteResult> // </GetQuoteResponse> // </soap:Body> // </soap:Envelope> // Navigate to soap:Body CkXml_FirstChild2(soapResp); // Navigate to GetQuoteResponse CkXml_FirstChild2(soapResp); // Navigate to GetQuoteResult CkXml_FirstChild2(soapResp); // The actual XML response is the data within GetQuoteResult: xmlResp = CkXml_Create(); CkXml_LoadXml(xmlResp,CkXml_content(soapResp)); // Display the XML response: printf("%s\n",CkXml_getXml(xmlResp)); } CkHttpRequest_Dispose(req); CkHttp_Dispose(http); CkXml_Dispose(soapReq); CkXml_Dispose(soapResp); CkXml_Dispose(xmlResp); } |
Need a specific example? Send a request to support@chilkatsoft.com
© 2000-2010 Chilkat Software, Inc. All Rights Reserved.