Jump to content

SOAP request and parsed response in classic ASP


tartnboy

Recommended Posts

OK, first and foremost, am using classic ASP as that is what I have to work with. All electronic forms in my company are currently in classic ASP. Too many of them to move to .net any time soon. That said, I have written an html form that includes sending a SOAP request to our CRM (ticketing system) which is vendor hosted. They are supplying the .net web service to the CRM's database. This will send back a response not only of a successful receipt, but also a ticket number which I am to display to the customer's screen. I am pretty comfortable with the sending part, I think. It is the response I am not so sure about. I've done XML responses through a web service before; however, I've never had a response I would have to parse before. Here are the questions that I have: 1. Are the request and response generally coded in the same envelope or separately? 2. I'm pretty comfortable displaying text received in a response using xmlhttp.responseText, but HOW would you parse the SOAP response in classic ASP? Below is the code I have for the Request:

   strXML = ""  strXML = strXML & "<?xml version=""1.0"" encoding=""UTF-8""?>" & strCR  strXML = strXML & "<SOAP-ENV:Envelope xmlns:SOAP-ENV='http://schemas.xmlsoap.org/soap/envelope/' xmlns:SOAP-ENC='http://schemas.xmlsoap.org/soap/encoding/' xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' xmlns:xsd='http://www.w3.org/2001/XMLSchema'>" & strCR  strXML = strXML & "  <SOAP-ENV:Header>" & strCR  strXML = strXML & "    <m:header xmlns:m='http://VenderURL'>" & strCR  strXML = strXML & "	  <docType>Esr Client</docType>" & strCR  strXML = strXML & "	  <version>3.0</version>" & strCR  strXML = strXML & "	  <sender type='CUSTSYSID'>WIN</sender>" & strCR  strXML = strXML & "	  <receiver type='CUSTSYSID'>CCC</receiver>" & strCR  strXML = strXML & "	  <requestSyncType>synchronous</requestSyncType>" & strCR  strXML = strXML & "	  <deployment.Mode>test</deployment.Mode>" & strCR  strXML = strXML & "	  <partner type='CUSTSYSID'>" & String & "</partner>" & strCR  strXML = strXML & "	  <transactionId>" & IntPONumber & "</transactionId>" & strCR  strXML = strXML & "	  <timestamp>" & strTimeStamp & "</timestamp>" & strCR  strXML = strXML & "    </m:header>" & strCR  strXML = strXML & "  </SOAP-ENV:Header>" & strCR  strXML = strXML & "  <SOAP-ENV:Body>" & strCR  strXML = strXML & "    <m:serviceRequest xmlns:m='http://VendorURL' action='String'>" & strCR  strXML = strXML & "	  <ticketInfo ticketNumber='String'>" & strCR  strXML = strXML & "	    <refTicketNumber>" & "intPONumber" & "</refTicketNumber>" & strCR  strXML = strXML & "	    <openedDateStamp>" & strTimeStamp & "</openedDateStamp>" & strCR  strXML = strXML & "	    <sentDateStamp>" & strTimeStamp & "</sentDateStamp>" & strCR  strXML = strXML & "	    <transDateStamp>" & strTimeStamp & "</transDateStamp>" & strCR  strXML = strXML & "	    <problemDescription>" & "strCCDescription" & "</problemDescription>" & strCR  strXML = strXML & "	    <resolution code='String' timeStamp='YYYY-MM-DDTHH:MM:SS'>" & String & "</resolution>" & strCR  strXML = strXML & "	    <shortDescription>" & strSubject & "</shortDescription>" & strCR  strXML = strXML & "	    <status>2</status>" & strCR  strXML = strXML & "	    <priority internalCode='3'/>" & strCR  strXML = strXML & "	    <severity code='3'/>" & strCR  strXML = strXML & "	    <sla contractId=””>" & strCR  strXML = strXML & "		  <contractName>Winn-Dixie SLA Contract</contractName>" & strCR  strXML = strXML & "	    </sla>" & strCR  strXML = strXML & "	    <technician.id>" & strTechnician & "</technician>" & strCR  strXML = strXML & "	    <category name='IssueCode1'>INCIDENT</category>" & strCR  strXML = strXML & "	    <category name='IssueCode2'>HARDWARE</category>" & strCR  strXML = strXML & "	    <category name='IssueCode3'>BREAK / FIX</category>" & strCR  strXML = strXML & "	  </ticketInfo>" & strCR  strXML = strXML & "   <entitlement>" & strCR  strXML = strXML & "	    <code>" & CustCode & "</code>" & strCR  strXML = strXML & "	  </entitlement>" & strCR  strXML = strXML & "	  <contact type='primary' vip=”false”>" & strCR  strXML = strXML & "	    <company>WINN-DIXIE</company>" & strCR  strXML = strXML & "	    <Email>WD REQ</Email>" & strCR  strXML = strXML & "	  </contact>" & strCR  strXML = strXML & "	  <serviceAddress site='0'>" & strCR  strXML = strXML & "	  </serviceAddress>" & strCR  strXML = strXML & "	  <equipment>" & strCR  strXML = strXML & "	    <model>" & part_no & "</model>" & strCR  strXML = strXML & "	  <description>" & strConfigItem & "</description>" & strCR  strXML = strXML & "	  </equipment>" & strCR  strXML = strXML & "	  <extrinsics name='FLEX2'>" & strPartDesc & "</extrinsics>" & strCR  strXML = strXML & "    </m:serviceRequest>" & strCR  strXML = strXML & "  <SOAP-ENV:Fault>" & strCR  strXML = strXML & "    <faultcode>SOAP-ENV:Client</faultcode>" & strCR  strXML = strXML & "    <faultstring>[ISS.0088.9134] Exception occurred while processing the body of the message</faultstring>" & strCR  strXML = strXML & "    <faultactor>http://b2bqc.compucom.com/soap</faultactor>" & strCR  strXML = strXML & "  </SOAP-ENV:Fault>" & strCR  strXML = strXML & "  </SOAP-ENV:Body>" & strCR  strXML = strXML & "</SOAP-ENV:Envelope>"	   ' End of Request section ' Call the webservice using POST  baseURL="[url="https://b2bqc.compucom.com/ws/CcEsrV4:provider"]https://b2bqc.compucom.com/ws/CcEsrV4:provider[/url]"   'Link for Production Environment  		    Set objXmlHttp = CreateObject("MSXML2.ServerXMLHTTP.3.0")		    objXmlHttp.setTimeouts toResolve, toConnect, toSend, toReceive				    objXmlHttp.Open "POST", baseURL, False		    objXMLHttp.Send(strXML)		  

Here's the code for the response:

 strXMLResponse = ""strXMLResponse = strXMLResponse & "<SOAP-ENV:Envelope xmlns:SOAP-ENV='[url="http://schemas.xmlsoap.org/soap/envelope/"]http://schemas.xmlsoap.org/soap/envelope/[/url]' xmlns:SOAP-ENC='[url="http://schemas.xmlsoap.org/soap/encoding/"]http://schemas.xmlsoap.org/soap/encoding/[/url]' xmlns:xsd='[url="http://www.w3.org/2001/XMLSchema"]http://www.w3.org/2001/XMLSchema[/url]'xmlns:xsi='[url="http://www.w3.org/2001/XMLSchema-instance"]http://www.w3.org/2001/XMLSchema-instance[/url]'>" & strCRstrXMLResponse = strXMLResponse &  "<SOAP-ENV:Body>" & strCRstrXMLResponse = strXMLResponse & "  <serviceResponse>" & strCRstrXMLResponse = strXMLResponse & "    <status code="?">string</status>" & strCRstrXMLResponse = strXMLResponse & "    <statusMsg>string</statusMsg>" & strCRstrXMLResponse = strXMLResponse & "    <ticketNumber>string</ticketNumber>" & strCRstrXMLResponse = strXMLResponse & "    <refTicketNumber>string</refTicketNumber>" & strCRstrXMLResponse = strXMLResponse & "  </ESR:serviceResponse>" & strCRstrXMLResponse = strXMLResponse & "</SOAP-ENV:Body>" & strCRstrXMLResponse = strXMLResponse & "</SOAP-ENV:Envelope>" ' XML Response from VendorresponseXML = xmlhttp.responseTextresponse.write("Your Ticket Number is: ") & "<b><font color='#cc0000' size='4'>" & responseXML & "</font></b>"

Any guidance anyone can provide would be greatlly appreciated. Thanks, BillM

  • Like 2
Link to comment
Share on other sites

  • 8 years later...

Bill, this is yourself, 8+ years later.  For anyone looking for the answer to this, this is the code I eventually came up with.

 

' beginning of XML data sent

	dim strXML, strXMLResponse, responseXMLCC

'set up xmlhttp to checkout server
Set objXmlHttp = Server.CreateObject("MSXML2.ServerXMLHTTP.6.0") 

'objXmlHttp.setTimeouts toResolve, toConnect, toSend, toReceive         
 objXmlHttp.setTimeouts 30000, 30000, 60000, 60000 'ms - resolve, connect, send, receive 
		
' Call the webservice using POST (defining the URL)

		baseURL="https://b2b...

' Start the SOAP envelop for REQUEST
		
		strXML = "<?xml version=""1.0"" encoding=""UTF-8""?>" & strCR
		strXML = strXML & "<soap:Envelope xmlns:soap=" & chr(34) & "http://www.w3.org/2003/05/soap-envelope" & chr(34) & strCR
		strXML = strXML & "   xmlns:ser=" & chr(34) & "http://b2b.compucom.com/serviceRequest_v4" & chr(34) & strCR
		strXML = strXML & "   xmlns:prov=" & chr(34) & "http://b2b.compucom.com/CcEsrV4/provider" & chr(34) & ">" & strCR
 		strXML = strXML & "  <soap:Header>" & strCR
 		strXML = strXML & "    <ser:esr docType=" & chr(34) & "ESR Client" & chr(34) & " transactionId=" & chr(34) & intPONumber & chr(34) &  " timestamp=" & chr(34) & strToday & chr(34) & " requestSyncType=" & chr(34) & "synchronous" & chr(34) & ">" & strCR 		
		strXML = strXML & "      <sender type=" & chr(34) & "CUSTSYSID" & chr(34) & ">WIN</sender>" & strCR
		strXML = strXML & "      <receiver type=" & chr(34) & "CUSTSYSID" & chr(34) & ">CCC</receiver>" & strCR
		strXML = strXML & "    </ser:esr>" & strCR
		strXML = strXML & "  </soap:Header>" & strCR
		strXML = strXML & "  <soap:Body>" & strCR
        strXML = strXML & "    <prov:openCase>" & strCR
		strXML = strXML & "      <ticketInfo>" & strCR
		strXML = strXML & "        <refTicketNumber>" & intPONumber & "</refTicketNumber>" & strCR
		strXML = strXML & "        <openedDateStamp>" & strToday & "</openedDateStamp>" & strCR
		strXML = strXML & "        <sentDateStamp>" & strToday & "</sentDateStamp>" & strCR
		strXML = strXML & "        <transDateStamp>" & strToday & "</transDateStamp>" & strCR
        strXML = strXML & "        <shortDescription>" & strCCSubject & "</shortDescription>" & strCR
	    strXML = strXML & "        <problemDescription>" & strCCDescription & "</problemDescription>" & strCR
		strXML = strXML & "       < status code=" & chr(34) & "2" & chr(34) & ">2</status>" & strCR
		strXML = strXML & "        <priority internalCode=" & chr(34) & "3" & chr(34) & "/>" & strCR
		strXML = strXML & "        <supportGroup>" & strAssignmentGrp & "</supportGroup>" & strCR
		strXML = strXML & "        <category name=" & chr(34) & "Category" & chr(34) & ">INCIDENT</category>" & strCR
		strXML = strXML & "        <category name=" & chr(34) & "Subcategory" & chr(34) & ">HARDWARE</category>" & strCR
		strXML = strXML & "        <category name=" & chr(34) & "CaseType" & chr(34) & ">BREAK / FIX</category>" & strCR
		strXML = strXML & " 	   <technician id=" & chr(34) & "!FSST_User" & chr(34) & "/>" & strCR
		strXML = strXML & "        <entitlement>" & strCR
		strXML = strXML & "          <code>" & strCustCode & "</code>" & strCR
		strXML = strXML & "        </entitlement>" & strCR	
		strXML = strXML & "      </ticketInfo>" & strCR
		strXML = strXML & "      <contact type=" & chr(34) & "primary" & chr(34) & ">" & strCR
		strXML = strXML & "        <company>Southeastern Grocers</company>" & strCR
		strXML = strXML & "        <lastName>" & strCCName & "</lastName>" & strCR
		strXML = strXML & "        <email>" & strUserType & strCCLoc & strBanner4 & "</email>" & strCR
		strXML = strXML & "        <phone countryCode=" & chr(34) &"1" & chr(34) & ">555-555-5555</phone>" & strCR
		strXML = strXML & "      </contact>" & strCR
		strXML = strXML & "      <serviceAddress site=" & chr(34) & "0" & chr(34) & "/>" & strCR
		strXML = strXML & "      <equipment>" & strCR
		strXML = strXML & "        <description>" & strConfigItem & "</description>" & strCR
		strXML = strXML & "      </equipment>" & strCR
		strXML = strXML & "      <extrinsics name=""FLEX2"">" & strFlex & "</extrinsics>" & strCR
		strXML = strXML & "    </prov:openCase>" & strCR
		strXML = strXML & "  </soap:Body>" & strCR
		strXML = strXML & "</soap:Envelope>"        
' End of XML Request body		

  objXmlHttp.Open "POST", baseURL, False, "username", "password" 
  objXmlHttp.setRequestHeader "Content-Type", "text/xml"
  objXmlHttp.setRequestHeader "Authorization", "Basic d2lubmRpeGllOkQxeCFl"
  objXMLHttp.Send(strXML)


responseXMLCC = ObjXmlHttp.responseText 

responseXMLCC = Replace(ResponseXMLCC,"OK","")   
responseXMLCC = Replace(ResponseXMLCC,"ok","")   
responseXMLCC = Replace(ResponseXMLCC,"Ok","")   
responseXMLCC = Replace(ResponseXMLCC,"OK ","")   
responseXMLCC = Replace(ResponseXMLCC,"ok ","")   
responseXMLCC = Replace(ResponseXMLCC,"Ok ","")   

	If strCableType = "WDX-90A052208" then strScannerCable = "USB Cable"
	If strCableType = "WDX-90A052042" then strScannerCable = "IBM Legacy Cable"

'response.write "Cable Type is " & strScannerCable & strCR
response.write("Your ServiceNow Incident Number is: ") & "<b><font color='#cc0000' size='2'>" & responseXMLCC & "</font></b><p />"
'response.write "strConfigItem is " & strConfigItem & "<p />"
'response.write "strPrinter is " & strPrinter

Dim strSearchString, strSearchFor
strSearchString = ResponseXMLCC
strSearchFor = "<status code=""200""></status>"
If InStr(1, strSearchString, strSearchFor) > 0 then
  'We found strSearchFor in strSearchString
  Response.Write " (Successful eForm Transmission)"
Else
  'We didn't find strSearchFor in strSearchString, so...
  ' *** Send an email to CompuComDepotFailures@segrocers.com if the eForm fails ***

strSubject = "Winn-Dixie XML SOAP FAILURE at location: " & strCCLoc & " at " & strToday
	
	    Set Mailer = Server.CreateObject("CDO.Message")
	    Mailer.From = strSender	 	
	    Mailer.BCC = "CompuComDepotFailures@segrocers.com"    
 	    Mailer.Subject = strSubject    
	    Mailer.HTMLBody = CStr(responseXMLCC)    
	    %></a><!--#include virtual="_include/eFormParts/SMTPConfig2.inc"--><%
	    Mailer.Send
	      If Err.Number = 0 then
	      Set Mailer = Nothing
			Response.Write "<p>" & strCR & "<p>" & strCR	
		Else
			Response.Write "Mail send failure. Error was " & Mailer.Response
		End if 
End if	
		Set Mailer = nothing



'response.write responseXML

'dim strXML (might work after other sections are deleted)

'set up xmlhttp to checkout server
Set objXmlHttp = Server.CreateObject("MSXML2.ServerXMLHTTP.6.0") 

'objXmlHttp.setTimeouts toResolve, toConnect, toSend, toReceive         
objXmlHttp.setTimeouts 30000, 30000, 60000, 60000 'ms - resolve, connect, send, receive 
		
' Call the webservice using POST (defining the URL)

baseURL="https://b2b.compucom.com/ws/CcEsrV4:provider"	  	'Link for Production Environment
'baseURL="https://b2bqc.compucom.com/ws/CcEsrV4:provider"	'Link for QA Environment (QC for CompuCom)

        
' ********** XML Response from ServiceNow ********************

strXMLResponse = "<soap-Env:Envelope xmlns:SOAP-ENV=""http://www.w3.org/2003/05/soap-envelope"" xmlns:xsd=""http://www.w3.org/2001/XMLSchema"" xmlns:xsi=""http://www.w3.org/2001/XMLSchema-instance"">" & strCR
strXMLResponse = strXMLResponse & "  <soap-Env:Header xmlns:SOAP-ENC=""http://www.w3.org/2003/05/soap-encoding""/>" & strCR
strXMLResponse = strXMLResponse & "    <soap-Env:Body>" & strCR
strXMLResponse = strXMLResponse & "      <ser-root:esrResponse xmlns:ser-root=""http://b2b.compucom.com/CcEsrV4/provider"">" & strCR
strXMLResponse = strXMLResponse & "        <status code=""200""></status>" & strCR
strXMLResponse = strXMLResponse & "        <status code=""400""></status>" & strCR
strXMLResponse = strXMLResponse & "        <status code=""500""></status>" & strCR
strXMLResponse = strXMLResponse & "        <ticketNumber></ticketNumber>" & strCR
strXMLResponse = strXMLResponse & "      </ser-root:esrResponse>" & strCR
strXMLResponse = strXMLResponse & "    </soap-Env:Body>" & strCR
strXMLResponse = strXMLResponse & "  </soap-Env:Envelope>"

  objXmlHttp.Open "POST", baseURL, False, "username", "password" 
  objXmlHttp.setRequestHeader "Content-Type", "text/xml"
  objXmlHttp.setRequestHeader "Authorization", "Basic d2lubmRpeGllOkQxeCFl"
  objXMLHttp.Send(strXMLResponse)

end If

 

 

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...