# Call Non-SOAP Web Service Compose a simple xml stream for a non-SOAP web service transaction. It will call web service http://[AS400_IP]:8181/myrxs/rxs3 which is included in the base install of the RPG-XML Suite. Note the [AS400_IP] address will need to be changed to that of the machine where RPG-XML Suite was installed. ## Source Code ```rpgle //******************************************************************************************* //@Author - Kato Integrations //@Desc: Compose a simple xml stream for a non-SOAP web service transaction. It will // call web service http://[AS400_IP]:8181/myrxs/rxs3 which is included in // the base install of the RPG-XML Suite. Note the [AS400_IP] address will need to be // changed to that of the machine where RPG-XML Suite was installed. //@Notes: //******************************************************************************************* H dftactgrp(*no) bnddir('RXSBND') /copy rxs,RXSCp RXS_* procedures & definitions // //Local Prototypes // D allHandler pr D pType value like(RXS_Type) D pXPath value like(RXS_XPath) D pData value like(RXS_XmlData) D pDataLen value like(RXS_Length) D errHandler pr D pCurLine 10i 0 value D pCurCol 10i 0 value D pErrStr 1024a value varying D gError ds likeds(RXS_Error) inz //Result of parse D gPrsData ds qualified inz D status 10a varying D msg 256a varying //Used for RXS_getUri API D gInCfg ds likeds(RXS_GetUriIn) inz D gReqData s like(RXS_XmlData) D gRspData s like(RXS_XmlData) D gRspHttpHdr s like(RXS_XmlData) /free reset gError; reset gPrsData; exsr compose; if gError.code <> *blanks; return; endif; exsr transmit; if gError.code <> *blanks; return; endif; exsr parse; RXS_log(RXS_DIAG: 'gPrsData.status=' + gPrsData.status); RXS_log(RXS_DIAG: 'gPrsData.msg=' + gPrsData.msg); *inlr = *on; begsr compose; monitor; RXS_initTplEng(RXS_VAR: *omit: *omit: *omit: *omit: *on); RXS_loadTpl('geturi3.tpl'); RXS_updVar('residential': 'true'); RXS_updVar('title': 'Mr.'); RXS_updVar('first': 'Sample'); RXS_updVar('last': 'Resident'); RXS_updVar('street': '123 Center Rd'); RXS_updVar('cty': 'Mankato'); RXS_updVar('state': 'MN'); RXS_updVar('zip': '56001'); RXS_wrtSection('PostAdr_begin'); RXS_updVar('phone': '123-123-1234'); RXS_wrtSection('phone'); RXS_updVar('phone': '321-321-4321'); RXS_wrtSection('phone'); RXS_wrtSection('PostAdr_end'); gReqData = RXS_getBuffData(*on); //*on=clear buffer after retrieving. on-error; gError = RXS_catchError(); endmon; endsr; begsr transmit; monitor; //Note the below IP address needs to be changed to that of the iSeries where //the RPG-XML Suite was installed. Also note that if a different value was used //for the name of the RXS instance than 'myrxs' that should be specified in the //below URL. gInCfg.URI = 'http://192.168.0.11/myrxs/rxs3'; gInCfg.Port = 8181; gInCfg.Debug = RXS_YES; RXS_getUri(gInCfg: gReqData: gRspData: gRspHttpHdr); on-error; gError = RXS_catchError(); endmon; endsr; begsr parse; monitor; RXS_allElemContentHandler(%paddr(allHandler)); RXS_allAttrHandler(%paddr(allHandler)); RXS_parse(gRspData: RXS_VAR: %paddr(errHandler)); on-error; gError = RXS_catchError(); endmon; endsr; /end-free //------------------------------------------------------------------------------------------- //@Author: Kato Integrations //@Desc: //@Notes: There are four events that your program can be notified of through the allHandler // sub procedure and they are passed in the pEvntType parm. An event is triggered // as the parser reads the document top down, left to right (same way you read the // newspaper). Note that you will only be notified of events you specified before the // call to RXS_parse by using API's RXS_allElemBegHandler, RXS_allElemContentHandler, // RXS_allElemEndHandler, and RXS_allAttrHandler. // // The four events and their values (note that these can all be overidden by // changing the RXSCFG file or by doing a temporary override on the RXS_parse command) // // Element Begin = '>' -- Placed at end of string (i.e. '/elem>') // Element Content = '/' -- Placed at end of string (i.e. '/elem/') // Element End = '/>' -- Placed at end of string (i.e. '/elem/>') // Attribute = '@' -- Placed between the elem and attr (i.e. '/elem@attr') // // The most common events you will use are Element Content and Attribute simply // because these are the two that provide business data via the pData parm on the // allHandler procedure interface. Events Element Begin and Element End are very // helpful when you have repeating XML data. You can then use the Begin and End // events to do a CLEAR and WRITE to a PF record respectively. Remember that // in-between the Element Begin and Element End events you will be notified of all the // element content, which means that after the CLEAR (i.e. Element Begin event) you // can place data into the PF record until you reach the Element End event at which // time you can do a WRITE of that record because it has now been populated with data. //------------------------------------------------------------------------------------------- P allHandler b D allHandler pi D pEvntType value like(RXS_Type) D pXPath value like(RXS_XPath) D pData value like(RXS_XmlData) D pDataLen value like(RXS_Length) /free select; when pXPath = '/response@status'; gPrsData.status = pData; when pXPath = '/response/'; gPrsData.msg = pData; endsl; /end-free P e //------------------------------------------------------------------------------------------- //@Author: Kato Integrations //@Desc: //------------------------------------------------------------------------------------------- P errHandler B D errHandler PI D pCurLine 10i 0 value D pCurCol 10i 0 value D pErrStr 1024a value varying /free gError.code = 'GETURI3001'; gError.severity = 100; gError.pgm = 'GETURI3.errHandler'; gError.text = 'Line:' + %char(pCurLine) + ' Col:' + %char(pCurCol) + ' ' + pErrStr; /end-free P E ``` ## Template File ```xml ::PostAdr_begin .:first:. .:last:. .:street:. .:cty:. .:state:. .:zip:. ::phone .:phone:. ::PostAdr_end ``` ## Sample XML Request ```xml Egan Jones 123 Fake Street Mankato MN 56001 222-444-5555 ``` ## Sample XML Response ```xml Postadr for Egan Jones has been processed. ```