You are on page 1of 10

/* io-consulting.

com */ /* Beginning of Topic 1 - Consuming a Web Service */

Sample WSDL: http://www.gama-system.com/webservices/servertime.asmx?WSDL /* -------------------------------------------------------------------Begin GetTime PeopleCode---------------------------This PeopleCode was placed in the FieldChange event for a Pushbutton */ Local string &Payload, &ResponseStr; Local Message &Msg, &ReplyMsg; Local XmlDoc &Xml, &XmlDoc2; &Payload = "<?xml version='1.0'?><m:GetTime xmlns:m='http://www.gamasystem.com/webservices'/>"; &Xml = CreateXmlDoc(&Payload); &Msg = CreateMessage(Operation.GETTIME, %IntBroker_Request); &Msg.SetXmlDoc(&Xml); &ReplyMsg = %IntBroker.SyncRequest(&Msg); /* The returned object is a Message Object */ If All(&ReplyMsg) Then &ResponseStr = &ReplyMsg.GenXMLString(); TRN_DERIVED_XX.RAWXML1 = &ResponseStr; Else WinMessage("Error. No reply", 0); End-If; /* Process the request */ &XmlDoc2 = &ReplyMsg.GetXmlDoc(); /* The GetXMLDoc method (a message object method) retrieves the message data as an XmlDoc object. See XMLDoc methods and properties. */ &soapReq = CreateSOAPDoc(); &soapReq.XmlDoc = &XmlDoc2; &OK = &soapReq.ValidateSOAPDoc(); rem &parmName = &soapReq.GetParmName(1); &parmValue = &soapReq.GetParmValue(1); /* Parsing out the value of the first parameter in the response */ TRN_DERIVED_XX.DESCR1 = "Time: " | &parmValue; /* -------------------------------------------------------------------End GetTime PeopleCode-------------------------*/ /* -----------------------------------------------------------------Begin GetDate PeopleCode---------------------------This PeopleCode was placed in the FieldChange event for a Pushbutton */ Local string &Payload, &ResponseStr; Local Message &Msg, &ReplyMsg; Local XmlDoc &Xml, &XmlDoc2; &Payload = "<?xml version='1.0'?><m:GetDate xmlns:m='http://www.gamasystem.com/webservices'/>"; &Xml = CreateXmlDoc(&Payload); &Msg = CreateMessage(Operation.GETDATE, %IntBroker_Request); &Msg.SetXmlDoc(&Xml);

&ReplyMsg = %IntBroker.SyncRequest(&Msg); /* The returned object is a Message Object */ If All(&ReplyMsg) Then &ResponseStr = &ReplyMsg.GenXMLString(); TRN_DERIVED_XX.RAWXML1 = &ResponseStr; Else WinMessage("Error. No reply", 0); End-If; /* Process the request */ &XmlDoc2 = &ReplyMsg.GetXmlDoc(); /* The GetXMLDoc method (a message object method) retrieves the message data as an XmlDoc object. See XMLDoc methods and properties. */ &soapReq = CreateSOAPDoc(); &soapReq.XmlDoc = &XmlDoc2; &OK = &soapReq.ValidateSOAPDoc(); rem &parmName = &soapReq.GetParmName(1); &parmValue = &soapReq.GetParmValue(1); /* Parsing out the value of the first parameter in the response */ TRN_DERIVED_XX.DESCR1 = "Date: " | &parmValue; /* -------------------------------------------------------------------End GetDate PeopleCode-------------------------*/ /* End of Topic 1 - Consuming a Web Service */

/*---------------------------------------------------------------------------------------------------------------------------------*/ /* Beginning of Topic 2 - Creating a Message-Based Web Service */

Schema for Request Message: --------------------------<?xml version="1.0"?> <xs:schema targetNamespace="http://peoplesoft.com/TestRequest" xmlns:xs="http://www.w3.org/2001/XMLSchema"> <xs:element name="Test"> <xs:complexType> <xs:sequence> <xs:element name="Text" type="xs:string"/> </xs:sequence> </xs:complexType> </xs:element> </xs:schema> ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Schema for Response Message: ---------------------------<?xml version="1.0"?> <xs:schema targetNamespace="http://peoplesoft.com/TestResponse" xmlns:xs="http://www.w3.org/2001/XMLSchema"> <xs:element name="Test"> <xs:complexType> <xs:sequence>

<xs:element name="ResponseMessage" type="xs:string"/> </xs:sequence> </xs:complexType> </xs:element> </xs:schema> ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ /* Begin Handler PeopleCode. Application Package */ Placed in an Application Class in an

import PS_PT:Integration:IRequestHandler; class InboundSyncRequestHandler implements PS_PT:Integration:IRequestHandler method InboundSyncRequestHandler(); method onRequest(&MSG As Message) Returns Message; method onError(&MSG As Message) Returns string; end-class; method InboundSyncRequestHandler end-method; method onRequest /+ &MSG as Message +/ /+ Returns Message +/ /+ Extends/implements PS_PT:Integration:IRequestHandler.OnRequest +/ Local XmlDoc &Xmldoc; Local File &File; Local XmlNode &RootNode, &DescNode; Local Message &Response; Local string &Xmldata, &Descr, &Comments, &ParmValue, &LastName, &FirstName, &City, &State, &Reply; Local SOAPDoc &SOAPReq; Local number &SOAPValid; /* Get the body of the incoming message */ &Xmldoc = &MSG.GetXmlDoc(); /* Here, the incoming message is written to a flat file. */ /* &File = GetFile("HttpRequest.txt", "W"); &File.WriteString(&Xmldoc.GenXmlString()); &File.Close(); */ This is optional

/* Parsing out the incoming value in the inbound request message */ &SOAPReq = CreateSOAPDoc(); &SOAPReq.XmlDoc = &Xmldoc; &SOAPValid = &SOAPReq.ValidateSOAPDoc(); rem &parmName = &soapReq.GetParmName(1); &ParmValue = &SOAPReq.GetParmValue(1); /* Create the response message */ &Response = CreateMessage(Operation.TRN_DEMO_SERVICE_OP, %IntBroker_Response); /* Create the body for the response message */ &Xmldata = "<?xml version='1.0'?><Test/>";

&Xmldoc = CreateXmlDoc(&Xmldata); &RootNode = &Xmldoc.DocumentElement; &DescNode = &RootNode.AddElement("ResponseMessage"); /* Here, I have used a table (PS_TRN_CRSE_TBL_XX) as an example to show that we can select data from any table or view in the database. There is nothing else in this transaction that is specifically tied to this table. Select from whatever table you want to use. */ SQLExec("SELECT DESCR, COMMENTS FROM PS_TRN_CRSE_TBL_XX WHERE COURSE = :1", &ParmValue, &Descr, &Comments); &Reply = &Descr | ": " | &Comments; &DescNode.NodeValue = "This is the response message: " | &Reply; <* /* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */ /* Another example: you can receive an EMPLID, and send back information about that person */ SQLExec("SELECT FIRST_NAME, LAST_NAME, CITY, STATE FROM PS_PERSONAL_DATA WHERE EMPLID = :1", &ParmValue, &FirstName, &LastName, &City, &State); /* Sample EMPLIDs in a Demo Database: FA0676, FAD0038, FADLCD0005 */

&Reply = &FirstName | " " | &LastName | " lives in " | &City | ", " | &State; &DescNode.NodeValue = "This is the response message. -- Time: " | %Time | " -- " | &Reply; /* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */ *> /* Add the body to the message */ &Response.SetXmlDoc(&Xmldoc); /* Return the response message */ Return &Response; end-method; method onError /+ &MSG as Message +/ /+ Returns String +/ /+ Extends/implements PS_PT:Integration:IRequestHandler.OnError +/ Local integer &MsgNumber, &MsgSetNumber; Local string &Str; &MsgNumber = &MSG.IBException.MessageNumber; &MsgSetNumber = &MSG.IBException.MessageSetNumber; &Str = &MSG.IBException.DefaultText; Return &Str; end-method; /* End Handler PeopleCode */ /* End of Topic 2 - Creating a Message-Based Web Service */ Date: " | %Date | "

/* io-consulting.com */

////////////////////////////////////////////////////////////////////////////////////////////////////////////// ///

PeopleSoft: Outgoing integrations with 3rd party web services


May 1, 2012

I was recently fortunate enough to be able to take PeopleSoft Integration Tools Rel 8.50 course through Oracle University. The course was very well taught, very informative and gave a good overview of PeopleSoft Integration Broker (and related technologies). The one whole in the course was the section dealing with third party integrations (aka getting PeopleSoft to talk with outside web services). The course didnt go into very much detail about consuming web services and writing code to send call those web services. I soon discovered that the the PeopleBooks didnt go into too much detail on the topic either. So I spent a great deal of time figuring out how to write the PeopleCode that would allow me to call a third party web service. The initial steps I took were as follows: I imported the WSDL using the WSDL import wizard. The process for doing this is straight forward and is pretty well documented in PeopleBooks (PeopleBooks

> Enterprise PeopleTools 8.51 PeopleBook: Integration Broker > Consuming Services).
I then proceeded to rename the service operations, message and routings to something that gave a clear indication of their purpose. The importing of the WSDL went quite smoothly. I ran into a roadblock when trying to code that would allow me to call (send a request to) the third party web service. At first I tried the following PeopleCode:

Local SOAPDoc &soapDoc; Local XmlDoc &xmlDoc; Local XmlNode &envNode; &soapDoc = CreateSOAPDoc(); &SOAPDoc.AddEnvelope(%SOAP_Custom); &envNode = &soapDoc.EnvelopeNode; &envNode.AddAttribute("xmlns:tem", "http://tempuri.org/"); &soapDoc.AddHeader(); &soapDoc.AddBody(); &soapDoc.AddMethod("HelloWorld"); &xmlDoc = CreateXMLDoc(&soapDoc.GenXMLString()); &rqst = CreateMessage(Operation.UW_OB_HELLOWORLD_RGLR_SY, %IntBroker_Request); &rqst.SetXmlDoc(&xmlDoc); &rspn. &IntBroker.SyncRequest(&rqst);

This PeopleCode produced a XML request message that follows:

<?xml version="1.0"?> <SOAP-ENV:Envelope xmlns:tem="http://tempuri.org/" xmlns:SOAPENV="http://schemas.xmlsoap.org/soap/envelope/"> <SOAP-ENV:Header/> <SOAP-ENV:Body> <HelloWorld/> </SOAP-ENV:Body> </SOAP-ENV:Envelope>
The problem is that the Web Service required a message in the following format:

<soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope" xmlns:tem="http://tempuri.org/"> <soap:Header/> <soap:Body> <tem:HelloWorld/> </soap:Body> </soap:Envelope>


After playing with the above code for a while I wasnt able to get PeopleCode to automatically generate a message with the appropriate format. So I than decided to manually create a message in the appropriate message. The next steps that I took were as follows: Use the XmlDoc class to build the SOAP envelope for the message. Use the XmlNode class to populate the frame of the message.

I then tried the following PeopleCode:

Local XmlDoc &xmlRqst, &xmlRspn; Local XmlNode &docTypeNode, &headerNode, &methodNode; Local Message &rqst, &rspn; &xmlRqst = CreateXmlDoc(""); &envNode = &xmlRqst.CreateDocumentElement("soap:Envelope", "http://www.w3.org/2003/05/soap-envelope"); &envNode.AddAttribute("xmlns:tem", "http://tempuri.org/"); &headerNode = &xmlRqst.DocumentElement.AddElement("soap:Header"); &bodyNode = &xmlRqst.DocumentElement.AddElement("soap:Body"); &methodNode = &bodyNode.AddElement("tem:HelloWorld"); &rqst = CreateMessage(Operation.UW_OB_HELLOWORLD_RGLR_SY, %IntBroker_Request); &rqst.SetXmlDoc(&xmlRqst); &rspn = %IntBroker.SyncRequest(&rqst);

This PeopleCode produced a XML request message that follows:

<soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope" xmlns:tem="http://tempuri.org/"> <soap:Header/> <soap:Body> <tem:HelloWorld/> </soap:Body> </soap:Envelope>


As you will note the code produced a SOAP message (request) in the appropriate format. The web service returned a SOAP message (response) in the following format:

<soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"> <soap:Body> <HelloWorldResponse xmlns="http://tempuri.org/"> <HelloWorldResult>Hello World</HelloWorldResult> </HelloWorldResponse> </soap:Body> </soap:Envelope>
PeopleSoft integration broker will peel off the envelope and body tags from the message.

Test third Party intergration w/ sample Peoplecode Using XMLDoc and SOAPDoc Database: H900GX0U 8.51.10 Used the WSDL at URL: http://wsf.cdyne.com/weatherws/weather.asmx?WSDL Consumed the WSDL for GETCITYFORECASTBYZIP Set security. The web service was obtained from http://wsf.cdyne.com/weatherws/weather.asmx which also has a sample message. 1. Tested with the service operation tester with the xml: <?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> <GetCityForecastByZIP xmlns="http://ws.cdyne.com/WeatherWS/"> <ZIP>01845</ZIP> </GetCityForecastByZIP> </soap:Body> </soap:Envelope> And got a valid response. 2. Tested with the xml (let the system soap it up) <?xml version="1.0"?> <GetCityForecastByZIP xmlns="http://ws.cdyne.com/WeatherWS/"> <ZIP>01845</ZIP> </GetCityForecastByZIP> Successful response. 3. Tested with Peoplecode A. Used XMLDoc class: Local string &payload, &responseStr, &zip; Local Message &msg, &reply; Local XmlDoc &xml; &payload = "<?xml version='1.0'?> <GetCityForecastByZIP xmlns='http://ws.cdyne.com/WeatherWS/'>"; &zip = "01845"; &payload = &payload | "<ZIP>" | &zip | "</ZIP> </GetCityForecastByZIP>"; &xml = CreateXmlDoc(&payload); &msg = CreateMessage(Operation.GETCITYFORECASTBYZIP, %IntBroker_Request); &msg.SetXmlDoc(&xml); &reply = %IntBroker.SyncRequest(&msg); If All(&reply) Then &responseStr = &reply.GenXMLString(); MessageBox(0, "", 0, 0, &responseStr); Else MessageBox(0, "", 0, 0, "Error. No reply"); End-If; which generated the message: <?xml version="1.0"?> <GetCityForecastByZIP

xmlns="http://ws.cdyne.com/WeatherWS/"><ZIP>01845</ZIP></GetCityFore castByZIP> and with the SOAP envelope (from SOAPUP = Y on Routing Connector: <?xml version="1.0" encoding="UTF-8"?><soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:wsa="http://schemas.xmlsoap.org/ws/2003/03/addressing" ><soapenv:Body> <GetCityForecastByZIP xmlns="http://ws.cdyne.com/WeatherWS/"><ZIP>01845</ZIP></GetCityFore castByZIP></soapenv:Body> </soapenv:Envelope> And got back the reply: <?xml version="1.0"?> <GetCityForecastByZIPResponse xmlns="http://ws.cdyne.com/WeatherWS/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> <GetCityForecastByZIPResult> <Success>true</Success> <ResponseText>City Found</ResponseText> <State>MA</State> <City>North Andover</City> <WeatherStationCity>Lawrence</WeatherStationCity> <ForecastResult> <Forecast> <Date>2012-01-06T00:00:00</Date> <WeatherID>3</WeatherID> <Desciption>Mostly Cloudy</Desciption> <Temperatures> <MorningLow/> <DaytimeHigh>44</DaytimeHigh> </Temperatures> etc. B. Using SOAPDoc: Local SOAPDoc &WthrDoc1; Local XmlDoc &request1; Local Message &msg1; Local Message &return_messages1; Local Rowset &Wthd_Rset1; Local XmlNode &EnvNode1, &MethNode1; &WthrDoc1 = CreateSOAPDoc(); &WthrDoc1.AddEnvelope(0); rem &EnvNode1 = &WthrDoc1.EnvelopeNode; &WthrDoc1.AddBody(); &WthrDoc1.AddMethod("GetCityForecastByZIP", 1); &MethNode1 = &WthrDoc1.MethodNode; &MethNode1.AddAttribute("xmlns", "http://ws.cdyne.com/WeatherWS/"); &Zip = "01845"; &WthrDoc1.AddParm("ZIP", &Zip); &ret1 = &WthrDoc1.ValidateSOAPDoc();

&request1 = &WthrDoc1.XmlDoc; &requeststr1 = &request1.GenFormattedXmlString(); MessageBox(0, "", 0, 0, &requeststr1); &msg1 = CreateMessage(Operation.GETCITYFORECASTBYZIP, %IntBroker_Request); &msg1.SetXmlDoc(&request1); &return_messages1 = %IntBroker.SyncRequest(&msg1); rem &Wthd_Rset = &return_mesages.getrowset(); &RetSTR1 = &return_messages1.GenXMLString(); MessageBox(0, "", 0, 0, &RetSTR1); The message generated was: <?xml version="1.0"?> <SOAP-ENV:Envelope xmlns:SOAPENC=" http://schemas.xmlsoap.org/soap/encoding/" xmlns:SOAPENV=" http://schemas.xmlsoap.org/soap/envelope/"> <SOAP-ENV:Body> <GetCityForecastByZIP xmlns="http://ws.cdyne.com/WeatherWS/"> <ZIP>01845</ZIP> </GetCityForecastByZIP> </SOAP-ENV:Body> </SOAP-ENV:Envelope> Response: <?xml version='1.0'?><GetCityForecastByZIPResponse xmlns="http://ws.cdyne.com/WeatherWS/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"><GetCityForecastByZIPRes ult><Success>true</Success><ResponseText>City Found</ResponseText><State>MA</State><City>North Andover</City><WeatherStationCity>Lawrence</WeatherStationCity><Forec astResult><Forecast><Date>2012-0106T00:00:00</Date><WeatherID>3</WeatherID><Desciption>Mostly Cloudy</Desciption><Temperatures><Mo etc.

You might also like