Passing CF variables in soap request
Hello,
I have been successful at getting a return from a third party API. Now I need to use that return (session key) on other soap requests in their API in order to retrieve information. I am storing the session key as a variable and was hoping to use this in subsequent calls to their API, however, it is not working. I am getting an error that tells me the session key is 'invalid and is outside the bounds of an array'. Does anyone know if it is possible to store and pass variables in susbsequest soap requests? Any help would be greatly appreciated!!!!
<!--- WSDL --->
<cfset wsdl_url="http://someurl?wsdl">
<!--- Compose SOAP message to send to Web Service--->
<cfsavecontent variable="soap"><?xml version="1.0" encoding="UTF-8" ?>
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<soapenv:Body>
<Login xmlns="http://www.siretechnologies.com/">
<LicenseKey>licenseKey</LicenseKey>
<Username>user</Username>
<Password>pass</Password>
<LicenseType>2</LicenseType>
<APIKey>APIKey</APIKey>
<SiteKey></SiteKey>
<CryptKey></CryptKey>
<WebOnly>false</WebOnly>
</Login>
</soapenv:Body>
</soapenv:Envelope>
</cfsavecontent>
<!--- Invoke web service to send message--->
<cfhttp url="#wsdl_url#" method="post" >
<cfhttpparam type="header" name="content-type" value="text/xml">
<cfhttpparam type="header" name="SOAPAction" value="http://www.siretechnologies.com/Login">
<cfhttpparam type="header" name="content-length" value="#len(soap)#">
<cfhttpparam type="header" name="charset" value="utf-8">
<cfhttpparam type="xml" name="message" value="#trim(soap)#">
</cfhttp>
<p><cfoutput>#xmlFormat(cfhttp.fileContent)#</cfoutput> </p>
<cfset MyXml = XmlParse(cfhttp.fileContent)>
<cfdump var="#MyXml#">
<cfset responseNodes = xmlSearch(MyXml,"//*[ local-name() = 'LoginResponse' ]")>
<cfdump var="#responseNodes#">
<cfoutput>
<cfloop from="1" to="#arraylen(responseNodes)#" index="i">
<cfset BookXML = xmlparse(responseNodes)>
<cfset SesKey = "#BookXML.LoginResponse.LoginResult.XmlText#">
<b>SessionKey:</b> #BookXML.LoginResponse.LoginResult.XmlText#<br>
<b>Session Key:#SesKey#
</cfloop>
</cfoutput>
<!--- GETUserId, Next call to API--->
<cfset wsdl_url="http://someurl/sire.asmx?wsdl">
<cfset sesKey2 = "#SesKey#">
<!--- Compose SOAP message to send to Web Service--->
<cfsavecontent variable="soap"><?xml version="1.0" encoding="UTF-8" ?>
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<soapenv:Body>
<GetUserId xmlns="http://www.siretechnologies.com/">
<SessionKey>sesKey2</SessionKey>
<UserName>user</UserName>
</GetUserId>
</soapenv:Body>
</soapenv:Envelope>
</cfsavecontent>
