6 Replies Latest reply on Jun 8, 2011 8:41 AM by Ultimatorx

    Web services & Soap

    Ultimatorx

      Now webservice is supposed to be a breeze but i don't know what the problem is doing it with coldfusion

      The site I am trying to request from has this format.POST /test_paydirect/services/TransactionQueryWs.asmx HTTP/1.1

      Host: test.someurl.com
      Content-Type: application/soap+xml; charset=utf-8
      Content-Length: length
      
      <?xml version="1.0" encoding="utf-8"?>
      <soap12:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap12="http://www.w3.org/2003/05/soap-envelope">
        <soap12:Body>
          <getTransactionData xmlns="http://tempuri.org/">
            <product_id>string</product_id>
            <trans_ref>string</trans_ref>
          </getTransactionData>
        </soap12:Body>
      </soap12:Envelope>
      HTTP/1.1 200 OK
      Content-Type: application/soap+xml; charset=utf-8
      Content-Length: 
      length
      
      <?xml version="1.0" encoding="utf-8"?>
      <soap12:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap12="http://www.w3.org/2003/05/soap-envelope">
        <soap12:Body>
          <getTransactionDataResponse xmlns="http://tempuri.org/">
            <getTransactionDataResult>string</getTransactionDataResult>
          </getTransactionDataResponse>
        </soap12:Body>
      </soap12:Envelope>

       

      I crafted ths code after going through Ben Nadel's example at http://www.bennadel.com/blog/1809-Making-SOAP-Web-Service-Requests-With-ColdFusion-And-CFH TTP.htm and i came up with this

       

      <cfsavecontent variable="soapBody">

      <cfoutput>

       

      <?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>

          <getTransactionAcquirerData xmlns="http://test.someurl.com">

            <product_id>120</product_id>

            <trans_ref>9999999999</trans_ref>

          </getTransactionAcquirerData>

        </soap:Body>

       

      </soap:Envelope>

       

      </cfoutput>

      </cfsavecontent>

       

       

      <!---

      Now that we have our SOAP body defined, we need to post it as

      a SOAP request to the Campaign Monitor website. Notice that

      when I POST the SOAP request, I am NOT required to append the

      "WSDL" flag to the target URL (this is only required when you

      actually want to get the web service definition).

      --->

      <cfhttp

      url="https://test.someurl.comt/services/"

      method="post"

      result="httpResponse">

       

      <!---

      Most SOAP action require some sort of SOAP Action header

      to be used.

      --->

      <cfhttpparam

      type="header"

      name="SOAPAction"

      value="""http://test.someurl.com/"""

      />

       

      <!---

      I typically use this header because CHTTP cannot handle

      GZIP encoding. This "no-compression" directive tells the

      server not to pass back GZIPed content.

      --->

      <cfhttpparam

      type="header"

      name="accept-encoding"

      value="no-compression"

      />

       

      <!---

      When posting the SOAP body, I use the CFHTTPParam type of

      XML. This does two things: it posts the XML as a the BODY

      and sets the mime-type to be XML.

       

      NOTE: Be sure to Trim() your XML since XML data cannot be

      parsed with leading whitespace.

      --->

      <cfhttpparam

      type="xml"

      value="#trim( soapBody )#"

      />

       

      </cfhttp>

       

       

      <!---

      When the HTTP response comes back, our SOAP response will be

      in the FileContent atribute. SOAP always returns valid XML,

      even if there was an error (assuming the error was NOT in the

      communication, but rather in the data).

      --->

      <cfif find( "200", httpResponse.statusCode )>

       

      <!--- Parse the XML SOAP response. --->

      <cfset soapResponse = xmlParse( httpResponse.fileContent ) />

       

      <!---

      Query for the response nodes using XPath. Because the

      SOAP XML document has name spaces, querying the document

      becomes a little funky. Rather than accessing the node

      name directly, we have to use its local-name().

      --->

      <cfset responseNodes = xmlSearch(

      soapResponse,

      "//*[ local-name() = 'getTransactionAcquirerData' ]"

      ) />

       

      <!---

      Once we have the response node, we can use our typical

      ColdFusion struct-style XML node access.

      --->

      <cfoutput>

       

      Code: #responseNodes[ 1 ].Code.xmlText#

      <br />

      Success: #responseNodes[ 1 ].Message.xmlText#

       

      </cfoutput>

      <cfelse><cfoutput>zogbedinat</cfoutput>

      </cfif>

       

      I have been at sea for hours somebody pls help

        • 1. Re: Web services & Soap
          Reed Powell Level 3

          Well, to begin with I'm not sure that I would ever use the phrase "is a breeze" and "ColdFusion" and "SOAP" in the same sentence.  It's always as adventure to get the first iteration of working with a new WS up and running.  More importantly, can you tell us what is happening when you make the WS call via CFHTTP?  What does the response look like?  What is the status code?  To you get an XML document back, or just a message from their server?  If a message, what is it?  If it is an XML doc, does it have a faultstring specified?  Most of these can be answered with a CFDUMP of the cfhttp.filecontent var, and of xmlParse(cfhttp.filecontent) - although you'll want to be sure that the output is an XML doc before doing the second CFDUMP.  Give us more details, and we can probably help you out.

          -reed

          • 2. Re: Web services & Soap
            Ultimatorx Level 1

            Thanks Reese so far it returns a blank page. I'll be grateful, if you can have a look at it, I think I have many things wrong in adopting Ben's example including not understanding the underlying concept.

            https://testwebpay.interswitchng.com/test_paydirect/services/TransactionQueryWs.asmx

             

            I was requesting for the gettransactiondata using product_id 190 & trans_ref 9999999999

            i had already posted this earlier using a form and it is required that i use a web service to retrieve it.

            Thanks for your time

            • 3. Re: Web services & Soap
              Ultimatorx Level 1

              Hi Reed, when i did a  <cfdump

                var = #httpResponse.statusCode#>

              this is what i got

              Connection Failure. Status code unavailable.

              • 4. Re: Web services & Soap
                Ultimatorx Level 1

                <cfdump var=#httpResponse.filecontent#> returns "Connection Failure"

                • 5. Re: Web services & Soap
                  Reed Powell Level 3

                  Aha!  that is important information.  There are a number of causes of this, and sometimes it "just happens" out of the blue in scripts of mine that have been running for years with no problems.  it usually indicates that your request really isn't making it all the way to the webservice software on the remote server - sometimes not even making it out of your own server, which is why you don't get any decent error information returned.

                   

                  However, to get started, just do a Google search on "connection failure CFHTTP" and you'll see a lot of good writeups.  one of the more common causes is related to header compression.  Check out those postings and let us know how you progress.

                  -reed

                  • 6. Re: Web services & Soap
                    Ultimatorx Level 1

                    Thanks I solved the connection failure by uploading it to the production server and it runs what it eventually outputs is

                     

                     

                    120 9999999999 Code: #responseNodes[ 1 ].Code.xmlText#
                    Success: #responseNodes[ 1 ].Message.xmlText#

                     

                    as it is now it is not returning the desired output, it is simply returning back the stuff i put into it.

                    my attempt to dump the statuscodes, responsecodes etc returns an empty variable.

                    thanks

                     

                    Message was edited by: Ultimatorx