Chilkat
HOME
Android™
ASP
Visual Basic
VB.NET
C#
iOS (IPhone)
Objective-C
C++
C
MFC
Delphi
FoxPro
Java
Perl
PHP Extension
PHP ActiveX
Python
PowerShell
Ruby
SQL Server
VBScript
|
SOAP ExampleHow to send a SOAP request and get the XML response. LOCAL loReq LOCAL loHttp LOCAL lnSuccess LOCAL loSoapReq LOCAL lcDomain LOCAL lnPort LOCAL lnSsl LOCAL loResp LOCAL loSoapResp LOCAL loXmlResp loReq = CreateObject('Chilkat.HttpRequest') loHttp = CreateObject('Chilkat.Http') * Any string unlocks the component for the 1st 30-days. lnSuccess = loHttp.UnlockComponent("Anything for 30-day trial") IF (lnSuccess <> 1) THEN =MESSAGEBOX(loHttp.LastErrorText) QUIT ENDIF * 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> loSoapReq = CreateObject('Chilkat.Xml') loSoapReq.Encoding = "utf-8" loSoapReq.Tag = "soap:Envelope" loSoapReq.AddAttribute("xmlns:xsi","http://www.w3.org/2001/XMLSchema-instance") loSoapReq.AddAttribute("xmlns:xsd","http://www.w3.org/2001/XMLSchema") loSoapReq.AddAttribute("xmlns:soap","http://schemas.xmlsoap.org/soap/envelope/") loSoapReq.NewChild2("soap:Body","") loSoapReq.FirstChild2() loSoapReq.NewChild2("GetQuote","") loSoapReq.FirstChild2() loSoapReq.AddAttribute("xmlns","http://www.webserviceX.NET/") loSoapReq.NewChild2("symbol","MSFT") loSoapReq.GetRoot2() ? loSoapReq.GetXml() * Build an SOAP request. loReq.UseXmlHttp(loSoapReq.GetXml()) loReq.Path = "/stockquote.asmx" loReq.AddHeader("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. lcDomain = "www.webservicex.net" lnPort = 80 lnSsl = 0 loResp = loHttp.SynchronousRequest(lcDomain,lnPort,lnSsl,loReq) IF (loResp = NULL ) THEN ? loHttp.LastErrorText ELSE * The XML response is in the BodyStr property of the response object: loSoapResp = CreateObject('Chilkat.Xml') loSoapResp.LoadXml(loResp.BodyStr) * 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 loSoapResp.FirstChild2() * Navigate to GetQuoteResponse loSoapResp.FirstChild2() * Navigate to GetQuoteResult loSoapResp.FirstChild2() * The actual XML response is the data within GetQuoteResult: loXmlResp = CreateObject('Chilkat.Xml') loXmlResp.LoadXml(loSoapResp.Content) * Display the XML response: ? loXmlResp.GetXml() ENDIF |
© 2000-2010 Chilkat Software, Inc. All Rights Reserved.
Mail Component · .NET Email Component · ASP Mail Component · XML Parser