Welcome to the SRP Forum! Please refer to the SRP Forum FAQ post if you have any questions regarding how the forum works.

Using SRP_COM to Trigger SOAP Task

edited January 2016 in SRP Utilities
I need to trigger a web service by sending the following SOAP request:
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ser="http://service.XXXXXX.com/"> <soapenv:Header/> <soapenv:Body> <ser:respondToTasks> <taskInstanceKey>12345</taskInstanceKey> <taskstatus>SUCCESS</taskstatus> </ser:respondToTasks> </soapenv:Body> </soapenv:Envelope>
To this WSDL...

https://wwwxxxxxx.com/TaskCallbackBean/respondToTasks

Can I use SRP_COM handle this? If so do you have some examples?

Would I use XMLHTTP or MSSoap.SoapClient?

Thanks

Comments

  • Sending SOAP requests is no different than sending JSON (or any) HTTP request. SOAP is just the protocol for how the payload is formatted. The most complete tutorial for sending HTTP requests is in this blog post. If you scroll down to the heading "OpenInsight Example2 Code", you'll see a link to sample code using SRP_COM.
  • Kevin,

    Thanks for the response and link a lot of good info; but none of those examples fall under my current example as I'm short for time and trying to avoid a lot of trial and error... Plus we have't had to do much of this type of stuff over the years I'm trying to understand how to incorporate the following lines into the SRP_COM call...
    <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ser="http://service.xxxxx.com/"> <soapenv:Header/> <soapenv:Body> <ser:respondToTasks> <taskInstanceKey>12345</taskInstanceKey> <taskstatus>SUCCESS</taskstatus> </ser:respondToTasks> </soapenv:Body> </soapenv:Envelope>
    I know the URL will be:

    https://wwwxxxxxx.com/TaskCallbackBean/respondToTasks

    But confused on how to SET each value like “taskInstanceKey” and “taskstatus”… and then there is the " http://schemas.xmlsoap.org/soap/envelope/" xmlns:ser="http://service.xxxxx.com/" not sure how that plays into this... Can you give me a couple of examples using my scenario?

    Greatly appropriated.
  • First of all, let me apologize. I forgot that the sample I pointed you to only does a GET. It doesn't do a true web request. Let's see if I can give you better guidance.

    With any sort of web request, you have two components: headers and payload. The headers are standard HTTP headers, and servers require different ones. So, you might have to do some research there. Payload is the contents being sent, which in this case is SOAP.

    Here is a sample OI stored procedure that takes a URL, a Headers array (each field is a header, with each header being in the format Name-@VM-Value), and a Payload. It sets the headers, sends the payload, and returns the response.

    Compile Function Process_XML_SOAP_Sample(URL, Header, Payload) //////////////////////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////////////////////// // // This program is proprietary and is not to be used by or disclosed to others, nor is it to // be copied without written permission from SRP Computer Solutions, Inc. // // Name : Process_XML_SOAP // // Description: Transmits an XML SOAP request // // Notes: Takes the passed payload and header and transmits it to the URL site // // Parameters: // CtrlEntId [in] -- The fully qualified name of the control calling the promoted event // Event [in] -- The event being executed. See the Notes section regarding "PRE" events // Param1-15 [in] -- Additional event parameter holders // EventFlow [out] -- Set to 1 or 0 so the calling event knows whether or not to // chain forward. See comments in EVENT_SETUP insert // // History (Date, Initials, Notes) // 04/13/2007 pcs Original programmer // //////////////////////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////////////////////// $Insert APP_INSERTS If Assigned(URL) else URL = "" If Assigned(Header) else Header = "" If Assigned(Payload) else Payload = "" Response = "" Try2 = "" If URL AND Payload then GoSub Process_XML end Return Response Process_XML: Object = OLECreateInstance("Msxml2.XMLHTTP.3.0") Status = OleStatus() If Status then Response = "OLE Error code: ":Status end else rv = OLECallMethod(Object, "Open", "POST", url , "false") ; * Standard Status = OleStatus() If Status then Response = "OLE Error code: ":Status end else Continue = Yes$ If Header then NumHeaders = Count(Header<1>, @VM) + (Header<1> NE "") For HeadLoop = 1 to NumHeaders While Continue rv = OLECallMethod(Object, "setRequestHeader", Header<1, HeadLoop>, Header<2, HeadLoop>) Status = OleStatus() If OleStatus() then Response = "OLE Error code: ":Status Continue = No$ end Next HeadLoop end If Continue then rv = OLECallMethod(Object, "Send", Payload) Status = OleStatus() If Status then Response = "OLE Error code: ":Status end else Response = OLEGetPRoperty(Object, "responseText") Status = OleStatus() If Status then Response := Char(13):Char(10):Status end end end end end return

    Here is some code you can use to test the sample. It makes a request to Google and gets an error in response (the error is from Google, not from the code). It's not much, but gives you the idea.

    URL = "http://www.google.com" Payload = '<?xml version="1.0" encoding="us-ascii" ?><content><value>test</value></content>' Header = "" Response = Process_XML_SOAP_Sample(URl, Header, Payload)

    Let's start with that. If you have any other questions, let me know.
  • Paulo,

    To follow up on Kevin's response and circle it back to your original post:

    1. Fundamentally you are using XMLHTTP. This is the COM object that allows us to send HTTP requests to web servers.

    2. Kevin's code sample above uses the Revelation COM functions (OLECreateInstance, OLECallMethod, OLEGetProperty) to interact with the XMLHTTP object. You can also use SRP_COM to handle this for you. The blog article sample source code can be used to get an idea of the syntax.

    3. Regardless of the way you interact with the COM object, the SOAP XML is simply sent as the payload (also known as the POST body). The information that goes into the XML must be managed by you and you just send the entire XML string as a part of the payload (i.e., no special SET operation required.)
  • OK; I finally have time to return back to this... and I've been playing around with getting this to work but maybe I'm missing something... Using the initial info and parameters I submittted here's where I'm at and still have not been able to get-it working correctly.

    If SRP_Com(objXmlDoc, "CREATE", "Msxml2.XMLHTTP.3.0") then WsdlURL = "https://xxxxxxxxxxxxxxxxxx.com:443/TaskCallbackBean/task-callback" call SRP_COM(MyObj, "CALL", "open", "POST", WsdlURL) If SRP_COM("", "ERROR") then x = Msg(@Window, SRP_COM("", "ERROR")) end PayLoad = '<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ser="http://service.xxxxxx.com/">':CrLf$ PayLoad := ' <soapenv:Header/>':CrLf$ PayLoad := ' <soapenv:Body>':CrLf$ PayLoad := ' <ser:respondToTasks>':CrLf$ PayLoad := ' <taskInstanceKey>3458638</taskInstanceKey>':CrLf$ PayLoad := ' <taskstatus>SUCCESS</taskstatus>':CrLf$ PayLoad := ' </ser:respondToTasks>':CrLf$ PayLoad := ' </soapenv:Body>':CrLf$ PayLoad := '</soapenv:Envelope>':CrLf$ call SRP_Com(MyObj, "SET", "setRequestHeader", "Content-Type", "text/xml; charset=utf-8") *call SRP_Com(MyObj, "SET", "setRequestHeader", "Content-Length", Len(PayLoad)) *call SRP_Com(MyObj, "SET", "setRequestHeader", "SOAPAction", WsdlURL) call SRP_COM(MyObj, "CALL", "send", PayLoad) status = SRP_COM(MyObj, "GET", "responseXML") call SRP_Com(MyObj, "RELEASE") end else Error = SRP_Com("", "ERROR") end

    Should I be sending the Payload on the header or call send? I have tried both...

    What am I missing???

    Thanks

    Paulo
  • Paulo,

    As Kevin's sample code above indicates, you should be sending the Payload via the Send method. However, the API service you are connecting to might require Header content to be passed through as well, but that is something only you can determine based on the documentation available to you.

    You did not specify in what way this isn't working for you. Are you getting any status errors? Are you simply getting no response at all? By the way, I recommending adding a Error = SRP_Com("", "ERROR") check after each major SRP_Com call. That might also reveal some helpful information.

    Finally, I noticed that your Send method is in all lower-case. I have no idea if the method is case insensitive, but all of the examples I've seen have seen spell it as "Send".
  • Method names are case insensitive, so passing "send" is fine. I second Don's recommendation to check the ERROR after each call to see if it's failing at the COM level. If there are no COM errors, then you should be getting some kind of response from the server, even if it's an error.
  • MyObj gets assigned a unique number

    Only errors I'm getting is on the following 2 lines:

    call SRP_Com(MyObj, "SET", "setRequestHeader", 'Content-Type, text/xml; charset=utf-8') call SRP_Com(MyObj, "SET", "setRequestHeader","SOAPAction")

    Errors is: Property Not Found

    I tried changing the send to "send" but get not feedback on the "Send" call.

    I'm starting to wonder if this is firewall issue; is there an easy way to test this?

    Thanks
  • Change "SET" to "CALL". "setRequestHeader" is a method, not a property. This error has nothing to do with firewall.
  • Thanks for catch that... After changing to CALL now I get "invalid number of parameters" for both lines.
  • edited February 2016
    Paulo,

    That is correct. Your headers need a name and a value. So, 'Content-Type' would be the name (first parameter) and 'text/xml; charset=utf-8' would be your value (second parameter). I'm not sure what you are supposed to put as a value for the SOAPAction name, but if nothing else put an empty string.
  • Don,

    Thanks for the feedback... That helped... It's working now and here is the final code that works using SRP_COM.

    Equ CrLf$ to \0D0A\ WsdlURL = "https://xxxxxxxxxxxxxxxxxxx.com:443/TaskCallbackBean/task-callback" PayLoad = '<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ser="http://service.xxxxxxxxx.com/">':CrLf$ PayLoad := ' <soapenv:Header/>':CrLf$ PayLoad := ' <soapenv:Body>':CrLf$ PayLoad := ' <ser:respondToTasks>':CrLf$ PayLoad := ' <taskInstanceKey>3535366</taskInstanceKey>':CrLf$ PayLoad := ' <taskstatus>SUCCESS</taskstatus>':CrLf$ PayLoad := ' </ser:respondToTasks>':CrLf$ PayLoad := ' </soapenv:Body>':CrLf$ PayLoad := '</soapenv:Envelope>':CrLf$ If SRP_Com(MyObj, "CREATE", "Msxml2.XMLHTTP.3.0") then call SRP_COM(MyObj, "CALL", "open", "POST", WsdlURL, "false") ErrorTrigger = "CALL > Open > Post > ":WsdlURL gosub CheckForErrors call SRP_Com(MyObj, "CALL", "setRequestHeader", "Content-Type", "text/xml; charset=utf-8") ErrorTrigger = "CALL > setRequestHeader > Content-Type > text/xml; charset=utf-8" gosub CheckForErrors call SRP_COM(MyObj, "CALL", "Send", PayLoad) ErrorTrigger = "CALL > Send > PayLoad" gosub CheckForErrors SendPayloadStatus = SRP_COM(MyObj, "GET", "statusText") ErrorTrigger = "GET > statusText" gosub CheckForErrors call SRP_Com(MyObj, "RELEASE") end else ErrorTrigger = "CREATE > Msxml2.XMLHTTP.3.0" gosub CheckForErrors end

    Thanks
  • Paulo,

    Nice. Thanks for posting your working code. I'm sure that will help many others who will have to go through the same experience.
Sign In or Register to comment.