Re: How to process the XML results of a .NET Soap Web Service? -
05-19-2006
, 12:51 AM
The XML is
<?xml version="1.0" encoding="utf-8"?><soap:Envelope
xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"><soap:Body><GetCustomerDeliveryAddressR esponse
xmlns="http://tempuri.org/"><GetCustomerDeliveryAddressResult><?xml
version="1.0" encoding="utf-8"?>
<BusinessEntity xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://schemas.microsoft.com/crm/2006/WebServices">
<address2_city>Waiheke Island</address2_city>
<address2_line3>7</address2_line3>
<address2_postalcode>1240</address2_postalcode>
<contactid>592bbb3d-00d1-da11-8a8c-0003ff8a98e7</contactid>
<firstname>SUE</firstname>
<lastname>IRVINE</lastname>
<new_address2_country name="New
Zealand">1</new_address2_country>
<new_address2_line4>Te Makiri Road</new_address2_line4>
<new_address2_line5>Onetangi</new_address2_line5>
<new_title name="Mrs">1</new_title>
</BusinessEntity></GetCustomerDeliveryAddressResult></GetCustomerDeliveryAddressResponse></soap:Body></soap:Envelope>
The program that fetches it and tires to unpack it is,
0001: *
0002: * FIRST DEMO WORKING PROGRAM FOR Simple Object Access Protocol
0003: * WILLIAM NESHAM - MARCH 2006
0004: *
0005: PROMPT ""
0006: *
0007: SYSMES=""
0008: *
0009: *** OPEN FILES ***
0010: *
0011: OPEN'','WORK.FILE' TO WFL ELSE
0012: SYSMES = "CANT OPEN WORK.FILE"
0013: GOSUB 99999
0014: GOTO 999
0015: END
0016: *
0017: *
0018: PRINT @(25,1):@(-3):"Demonstration Program for SOAP (
SOAPXML ) "
0019: PRINT @(5,5):"This program demonstrates that customer data"
0020: PRINT @(5,6):"can be fetched from a Microsoft CRM
Database."
0021: 10: PRINT @(5,8):@(-3):"Enter customer number "
0022: PRINT @(30,8):
0023: INPUT CUSTNO
0024: IF CUSTNO = "E" OR CUSTNO = "" THEN GOTO 999
0025: IF NOT(NUM(CUSTNO)) THEN
0026: SYSMES = "It says enter a number - doogh !!"
0027: GOSUB 99999
0028: GOTO 10
0029: END
0030: *
0031: $INCLUDE UNIVERSE.INCLUDE XML.H
0032: *
0033: * Proxy connection not required.
0034: *
0035: CRMX = ""
0036: CRMX :='<?xml version="1.0" encoding="utf-8"?>'
0037: CRMX :='<soap:Envelope
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xsd="http://www.w3.org/2001/XMLSche
ma" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">'
0038: CRMX :=" <soap:Body>"
0039: CRMX :='<GetCustomerDeliveryAddress
xmlns="http://tempuri.org/">'
0040: CRMX := "<CustomerNumber>":CUSTNO:"</CustomerNumber>"
0041: CRMX :="</GetCustomerDeliveryAddress>"
0042: CRMX :="</soap:Body>"
0043: CRMX :="</soap:Envelope>"
0044: *
0045: * just writing it away for de-bug purposes
0046: *
0047: WRITE CRMX ON WFL,"CRMX"
0048: *
0049: URL =
"http://Devpatchcrm01:8080/SingleAddressExtraction.asmx"
0050: *
0051: SoapAction =
"http://tempuri.org/GetCustomerDeliveryAddress"
0052: Timeout = 30000
0053: *
0054: * Create the Request
0055: *
0056: Ret = SoapCreateRequest(URL, SoapAction, SoapReq)
0057: IF Ret <> 0 THEN
0058: SYSMES = "Error in SoapCreateRequest " : Ret
0059: GOSUB 99999
0060: SYSMES = "If the error was '2' the process probably
timed out."
0061: GOSUB 99999
0062: GOTO 10
0063: END
0064: *
0065: PRINT @(0,9):@(-3):" First Step Successful.":
0066: *
0067: * Submit the Request
0068: *
0069: SETREQUEST.STATUS = soapSetRequestContent(SoapReq, CRMX,1)
0070: *
0071: Ret = SoapSubmitRequest(SoapReq, Timeout, RespHeaders,
RespData, SoapStatus)
0072: IF Ret <> 0 THEN
0073: SYSMES = "Error in SoapSubmitRequest"
0074: GOSUB 99999
0075: GOTO 999
0076: END
0077: *
0078: * Write the returning XML so that we know what we have.
0079: *
0080: WRITE RespData ON WFL,"RESPDATA"
0081: PRINT @(0,10):@(-3):" Second Step Successful ":
0082: *
0083: * Write the request
0084: *
0085: Ret = SOAPRequestWrite(SoapReq, WNREQ, 1)
0086: IF Ret <> 0 THEN
0087: SYSMES = "Error in Request Write " : Ret
0088: GOSUB 99999
0089: SYSMES = "If the error was '2' the process probably
timed out."
0090: GOSUB 99999
0091: GOTO 10
0092: END
0093: PRINT @(0,11):@(-3):" Third Step Successful ":
0094: * just writing it away for de-bug purposes
0095: WRITE WNREQ ON WFL,"CRMSOAP"
0096: *
0097: * Now start unpacking the response.
0098: *
0099: * First we had to remove the namespace at the head of the data.
0100: * A crude hammer and chisel job.
0101: *
0102: INDX1 = INDEX(RespData<1>,"xmlns=",1)
0103: INDX2 = INDX1+27
0104: RESPD1 = RespData<1>[1,INDX1-2]
0105: RESPD2 = RespData<1>[INDX2,9999]
0106: RespData<1> = RESPD1:RESPD2
0107: *
0108: Status = XDOMOpen(RespData, XML.FROM.STRING, DOMH)
0109: IF Status <> XML.SUCCESS THEN
0110: Status = XMLGetError(ECODE,EMESSAGE)
0111: SYSMES = "CODE AT 111 = ":ECODE:" MESSAGE = ":EMESSAGE
0112: GOSUB 99999
0113: GOTO 999
0114: END
0115: *
0116: PRINT @(0,12):@(-3):" Forth Step Successful ":
0117: *
0118: Status =
XDOMLocate(DOMH,'//GetCustomerDeliveryAddressResult','',NodeHandle)
0119: IF Status <> XML.SUCCESS THEN
0120: Status = XMLGetError(ECODE,EMESSAGE)
0121: SYSMES = "CODE AT 121 = ":ECODE:" MESSAGE = ":EMESSAGE
0122: GOSUB 99999
0123: GOTO 999
0124: END
0125: *
0126: Status = XDOMLocateNode(NodeHandle, XDOM.CHILD,
XDOM.FIRST.CHILD, XDOM.NONE, DOMNode2)
0127: IF Status <> XML.SUCCESS THEN
0128: Status = XMLGetError(ECODE,EMESSAGE)
0129: SYSMES = "CODE AT 129 = ":ECODE:" MESSAGE = ":EMESSAGE
0130: GOSUB 99999
0131: GOTO 999
0132: END
0133: *
0134: Status = XDOMGetNodeValue(DOMNode2, DOMOUTPUT)
0135: IF Status <> XML.SUCCESS THEN
0136: Status = XMLGetError(ECODE,EMESSAGE)
0137: SYSMES = "CODE AT 137 = ":ECODE:" MESSAGE = ":EMESSAGE
0138: GOSUB 99999
0139: GOTO 999
0140: END
0141: *
0142: * load the core of the XML string into a 2nd DOM object
0143: *
0144: Status = XDOMOpen(DOMOUTPUT, XML.FROM.STRING, DOMH2)
0145: IF Status <> XML.SUCCESS THEN
0146: Status = XMLGetError(ECODE,EMESSAGE)
0147: SYSMES = "CODE AT 147 = ":ECODE:" MESSAGE = ":EMESSAGE
0148: GOSUB 99999
0149: GOTO 999
0150: END
0151: *
0152: * Write away the core for de-bug purposes
0153: *
0154: WRITE DOMOUTPUT ON WFL,"DOMOUTPUT"
0155: *
0156: Status = XDOMWrite(DOMH2,xmlstring,XML.TO.STRING)
0157: IF Status <> XML.SUCCESS THEN
0158: Status = XMLGetError(ECODE,EMESSAGE)
0159: SYSMES = "CODE AT 159 = ":ECODE:" MESSAGE = ":EMESSAGE
0160: GOSUB 99999
0161: GOTO 999
0162: END
0163: *
0164: Status = XDOMLocate(DOMH2,'//firstname','',NodeHandle2)
0165: IF Status <> XML.SUCCESS THEN
0166: Status = XMLGetError(ECODE,EMESSAGE)
0167: SYSMES = "CODE AT 167 = ":ECODE:" MESSAGE = ":EMESSAGE
0168: GOSUB 99999
0169: GOTO 999
0170: END
0171: *
0172: * The program has errored at line 167 above
0173: * with message: Code = 10 Message = The location path
'//firstname' was not found.
0174: *
0175: PRINT @(0,16):"xmlstring = ":xmlstring ; INPUT AB
0176: PRINT @(0,22):"OK SO FAR " ; INPUT AB
0177: *
0178: 999:*** END OF PROGRAM ***
0179: *
0180: PRINT@(30,22):"Program Terminated":
0181: STOP
0182: *
0183: *
0184: 99999:***** SYSTEM MESSAGE ROUTINE *********
0185: *
0186: X=INT((76-LEN(SYSMES))/2) ; *** CENTRALIZE MESSAGE
***
0187: PRINT@(X,22):SYSMES:
0188: INPUT ANS,5
0189: PRINT@(0,22):@(-4):
0190: RETURN |