12 Replies Latest reply on Jul 2, 2009 10:11 AM by fs22

    Need Web Service Consumption Assistance

    fs22

      I am dipping my toe into the web service world and have a web service from Oracle that I am trying to consume. It is not working as I thought, so any pointers are appreciated.

       

      Here is the cfinvoke code...

       

      <cfinvoke
      webservice="http://erpintsrv1-dc-aus:7777/arWs/arWsSoapHttpPort?WSDL"
      method="customerXML"
      returnvariable="a_customerXMLResponseElement">
          <cfinvokeargument name="parameters" value="123456" />
      </cfinvoke>

       

      <cfdump var="#a_customerXMLResponseElement#">

       

      Here is the result...

       

      dump.jpg

       

      Here is the result from the Oracle interface...

       

      <env:Envelope
        xmlns:env="http://schemas.xmlsoap.org/soap/envelope/"
        xmlns:xsd="http://www.w3.org/2001/XMLSchema"
        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xmlns:ns0="http://xxas/integration/arws/ArWs.wsdl/types/">
      <env:Body>
        <ns0:customerXMLResponseElement>
         <result>
          <ROWSET>
           <ROW
             num="1">
            <CUSTOMER_NUMBER>123456</CUSTOMER_NUMBER>
            <CUSTOMER>MOUNTAIN BUILDING  SUPPLY, INC #8228</CUSTOMER>
            <PLATFORM>500</PLATFORM>
           </ROW>
          </ROWSET>
         </result>
        </ns0:customerXMLResponseElement>
      </env:Body>
      </env:Envelope>

      My thought was once I invoked the web service and dumped it to the page, I would see the above info (customer name, platform, etc.)  Instead, I seem to get java class names, methods, etc. Thoughts?

        • 1. Re: Need Web Service Consumption Assistance
          fs22 Level 1

          Anyone out there have any thoughts on this?

          • 2. Re: Need Web Service Consumption Assistance
            JR "Bob" Dobbs-qSBHQ2 Level 3

            Warning: this is a shot in the dark.

            Does a cfdump of a_customerXMLResponseElement.get_any() return an XML document or CF struct?  This Oracle service's "get_any()" method in your cfdump looks similar to how CF interprets .NET datasets returned from a web service.  In a .NET web service the SOAP type "any" is used when the results are to be sent as XML without a specific schema.

            Can you post the WSDL for this web service?

            • 3. Re: Need Web Service Consumption Assistance
              fs22 Level 1

              Here is the dump of getAny()...

               

              array
              1
              object of  org.apache.axis.message.MessageElement
              Class Nameorg.apache.axis.message.MessageElement
              Methods
              Method Return Type
              addAttribute(java.lang.String, java.lang.String,  javax.xml.namespace.QName)void
              addAttribute(java.lang.String, java.lang.String,  java.lang.String, java.lang.String)void
              addAttribute(java.lang.String, java.lang.String,  java.lang.String)void
              addAttribute(javax.xml.soap.Name,  java.lang.String)javax.xml.soap.SOAPElement
              addChild(org.apache.axis.message.MessageElement)void
              addChildElement(java.lang.String)javax.xml.soap.SOAPElement
              addChildElement(javax.xml.soap.SOAPElement)javax.xml.soap.SOAPElement
              addChildElement(java.lang.String,  java.lang.String, java.lang.String)javax.xml.soap.SOAPElement
              addChildElement(javax.xml.soap.Name)javax.xml.soap.SOAPElement
              addChildElement(java.lang.String,  java.lang.String)javax.xml.soap.SOAPElement
              addMapping(org.apache.axis.utils.Mapping)void
              addNamespaceDeclaration(java.lang.String,  java.lang.String)javax.xml.soap.SOAPElement
              addTextNode(java.lang.String)javax.xml.soap.SOAPElement
              cloneNode(boolean)org.w3c.dom.Node
              detachAllChildren()void
              equals(java.lang.Object)boolean
              getAllAttributes()java.util.Iterator
              getAsDOM()org.w3c.dom.Element
              getAsDocument()org.w3c.dom.Document
              getAsString()java.lang.String
              getAttribute(java.lang.String)java.lang.String
              getAttributeNS(java.lang.String,  java.lang.String)java.lang.String
              getAttributeNode(java.lang.String)org.w3c.dom.Attr
              getAttributeNodeNS(java.lang.String,  java.lang.String)org.w3c.dom.Attr
              getAttributeValue(java.lang.String)java.lang.String
              getAttributeValue(javax.xml.soap.Name)java.lang.String
              getAttributesEx()org.xml.sax.Attributes
              getChildElement(javax.xml.namespace.QName)org.apache.axis.message.MessageElement
              getChildElements(javax.xml.soap.Name)java.util.Iterator
              getChildElements(javax.xml.namespace.QName)java.util.Iterator
              getChildElements()java.util.Iterator
              getChildren()java.util.List
              getCompleteAttributes()org.xml.sax.Attributes
              getDeserializationContext()org.apache.axis.encoding.DeserializationContext
              getElementName()javax.xml.soap.Name
              getElementsByTagName(java.lang.String)org.w3c.dom.NodeList
              getElementsByTagNameNS(java.lang.String,  java.lang.String)org.w3c.dom.NodeList
              getEncodingStyle()java.lang.String
              getEnvelope()org.apache.axis.message.SOAPEnvelope
              getFixupDeserializer()org.apache.axis.encoding.Deserializer
              getHref()java.lang.String
              getID()java.lang.String
              getLength()int
              getName()java.lang.String
              getNamespacePrefixes()java.util.Iterator
              getNamespaceURI(java.lang.String)java.lang.String
              getObjectValue(java.lang.Class)java.lang.Object
              getObjectValue()java.lang.Object
              getOwnerDocument()org.w3c.dom.Document
              getPrefix(java.lang.String)java.lang.String
              getQName()javax.xml.namespace.QName
              getRealElement()org.apache.axis.message.MessageElement
              getRecorder()org.apache.axis.message.SAX2EventRecorder
              getTagName()java.lang.String
              getType()javax.xml.namespace.QName
              getValue()java.lang.String
              getValueAsType(javax.xml.namespace.QName)java.lang.Object
              getValueAsType(javax.xml.namespace.QName,  java.lang.Class)java.lang.Object
              getVisibleNamespacePrefixes()java.util.Iterator
              hasAttribute(java.lang.String)boolean
              hasAttributeNS(java.lang.String,  java.lang.String)boolean
              isRoot()boolean
              item(int)org.w3c.dom.Node
              output(org.apache.axis.encoding.SerializationContext)void
              publishContents(org.xml.sax.ContentHandler)void
              publishToHandler(org.xml.sax.ContentHandler)void
              removeAttribute(java.lang.String)void
              removeAttribute(javax.xml.soap.Name)boolean
              removeAttributeNS(java.lang.String,  java.lang.String)void
              removeAttributeNode(org.w3c.dom.Attr)org.w3c.dom.Attr
              removeContents()void
              removeNamespaceDeclaration(java.lang.String)boolean
              setAllAttributes(org.xml.sax.Attributes)void
              setAttribute(java.lang.String, java.lang.String,  java.lang.String)void
              setAttribute(java.lang.String,  java.lang.String)void
              setAttributeNS(java.lang.String,  java.lang.String, java.lang.String)void
              setAttributeNode(org.w3c.dom.Attr)org.w3c.dom.Attr
              setAttributeNodeNS(org.w3c.dom.Attr)org.w3c.dom.Attr
              setContentsIndex(int)void
              setEncodingStyle(java.lang.String)void
              setEndIndex(int)void
              setEnvelope(org.apache.axis.message.SOAPEnvelope)void
              setFixupDeserializer(org.apache.axis.encoding.Deserializer)void
              setNSMappings(java.util.ArrayList)void
              setName(java.lang.String)void
              setNamespaceURI(java.lang.String)void
              setObjectValue(java.lang.Object)void
              setQName(javax.xml.namespace.QName)void
              setRecorder(org.apache.axis.message.SAX2EventRecorder)void
              setType(javax.xml.namespace.QName)void
              setValue(java.lang.String)void
              toString()java.lang.String
              Fields
              Field Value
              short ATTRIBUTE_NODE2
              short CDATA_SECTION_NODE4
              short COMMENT_NODE8
              short DOCUMENT_FRAGMENT_NODE11
              short DOCUMENT_NODE9
              short DOCUMENT_POSITION_CONTAINED_BY16
              short DOCUMENT_POSITION_CONTAINS8
              short DOCUMENT_POSITION_DISCONNECTED1
              short DOCUMENT_POSITION_FOLLOWING4
              short DOCUMENT_POSITION_IMPLEMENTATION_SPECIFIC32
              short DOCUMENT_POSITION_PRECEDING2
              short DOCUMENT_TYPE_NODE10
              short ELEMENT_NODE1
              short ENTITY_NODE6
              short ENTITY_REFERENCE_NODE5
              short NOTATION_NODE12
              short PROCESSING_INSTRUCTION_NODE7
              short TEXT_NODE3
              java.util.ArrayList namespaces[undefined value]
              Parent Class

              • 4. Re: Need Web Service Consumption Assistance
                fs22 Level 1

                Here is the WSDL...

                 

                <?xml  version="1.0" encoding="UTF-8" ?>
                - <types>
                <element name="contactXMLElement" type="string" nillable="true" />
                - <element name="contactXMLResponseElement" nillable="true">
                - <complexType>
                - <sequence>
                <any />
                </sequence>
                </complexType>
                </element>
                <element name="contactXMLRowSetElement" type="string" nillable="true" />
                - <element name="contactXMLRowSetResponseElement" nillable="true">
                - <complexType>
                - <sequence>
                <any />
                </sequence>
                </complexType>
                </element>
                <element name="customerBillToXMLElement" type="string" nillable="true" />
                - <element name="customerBillToXMLResponseElement" nillable="true">
                - <complexType>
                - <sequence>
                <any />
                </sequence>
                </complexType>
                </element>
                <element name="customerBillToXMLRowSetElement" type="string" nillable="true" />
                - <element name="customerBillToXMLRowSetResponseElement" nillable="true">
                - <complexType>
                - <sequence>
                <any />
                </sequence>
                </complexType>
                </element>
                <element name="customerShipToXMLElement" type="string" nillable="true" />
                - <element name="customerShipToXMLResponseElement" nillable="true">
                - <complexType>
                - <sequence>
                <any />
                </sequence>
                </complexType>
                </element>
                <element name="customerShipToXMLRowSetElement" type="string" nillable="true" />
                - <element name="customerShipToXMLRowSetResponseElement" nillable="true">
                - <complexType>
                - <sequence>
                <any />
                </sequence>
                </complexType>
                </element>
                <element name="customerXMLElement" type="string" nillable="true" />
                - <element name="customerXMLResponseElement" nillable="true">
                - <complexType>
                - <sequence>
                <any />
                </sequence>
                </complexType>
                </element>
                <element name="customerXMLRowSetElement" type="string" nillable="true" />
                - <element name="customerXMLRowSetResponseElement" nillable="true">
                - <complexType>
                - <sequence>
                <any />
                </sequence>
                </complexType>
                </element>
                <element name="salesrepXMLElement" type="string" nillable="true" />
                - <element name="salesrepXMLResponseElement" nillable="true">
                - <complexType>
                - <sequence>
                <any />
                </sequence>
                </complexType>
                </element>
                <element name="salesrepXMLRowSetElement" type="string" nillable="true" />
                - <element name="salesrepXMLRowSetResponseElement" nillable="true">
                - <complexType>
                - <sequence>
                <any />
                </sequence>
                </complexType>
                </element>
                </schema>
                </types>
                - <message name="ArWs_contactXML">
                <part name="parameters" element="ns1:contactXMLElement" />
                </message>
                - <message name="ArWs_contactXMLResponse">
                <part name="result" element="ns1:contactXMLResponseElement" />
                </message>
                - <message name="ArWs_contactXMLRowSet">
                <part name="parameters" element="ns1:contactXMLRowSetElement" />
                </message>
                - <message name="ArWs_contactXMLRowSetResponse">
                <part name="result" element="ns1:contactXMLRowSetResponseElement" />
                </message>
                - <message name="ArWs_customerBillToXML">
                <part name="parameters" element="ns1:customerBillToXMLElement" />
                </message>
                - <message name="ArWs_customerBillToXMLResponse">
                <part name="result" element="ns1:customerBillToXMLResponseElement" />
                </message>
                - <message name="ArWs_customerBillToXMLRowSet">
                <part name="parameters" element="ns1:customerBillToXMLRowSetElement" />
                </message>
                - <message name="ArWs_customerBillToXMLRowSetResponse">
                <part name="result" element="ns1:customerBillToXMLRowSetResponseElement" />
                </message>
                - <message name="ArWs_customerShipToXML">
                <part name="parameters" element="ns1:customerShipToXMLElement" />
                </message>
                - <message name="ArWs_customerShipToXMLResponse">
                <part name="result" element="ns1:customerShipToXMLResponseElement" />
                </message>
                - <message name="ArWs_customerShipToXMLRowSet">
                <part name="parameters" element="ns1:customerShipToXMLRowSetElement" />
                </message>
                - <message name="ArWs_customerShipToXMLRowSetResponse">
                <part name="result" element="ns1:customerShipToXMLRowSetResponseElement" />
                </message>
                - <message name="ArWs_customerXML">
                <part name="parameters" element="ns1:customerXMLElement" />
                </message>
                - <message name="ArWs_customerXMLResponse">
                <part name="result" element="ns1:customerXMLResponseElement" />
                </message>
                - <message name="ArWs_customerXMLRowSet">
                <part name="parameters" element="ns1:customerXMLRowSetElement" />
                </message>
                - <message name="ArWs_customerXMLRowSetResponse">
                <part name="result" element="ns1:customerXMLRowSetResponseElement" />
                </message>
                - <message name="ArWs_salesrepXML">
                <part name="parameters" element="ns1:salesrepXMLElement" />
                </message>
                - <message name="ArWs_salesrepXMLResponse">
                <part name="result" element="ns1:salesrepXMLResponseElement" />
                </message>
                - <message name="ArWs_salesrepXMLRowSet">
                <part name="parameters" element="ns1:salesrepXMLRowSetElement" />
                </message>
                - <message name="ArWs_salesrepXMLRowSetResponse">
                <part name="result" element="ns1:salesrepXMLRowSetResponseElement" />
                </message>
                - <portType name="arWs">
                - <operation name="contactXML">
                <input message="tns:ArWs_contactXML" />
                <output message="tns:ArWs_contactXMLResponse" />
                </operation>
                - <operation name="contactXMLRowSet">
                <input message="tns:ArWs_contactXMLRowSet" />
                <output message="tns:ArWs_contactXMLRowSetResponse" />
                </operation>
                - <operation name="customerBillToXML">
                <input message="tns:ArWs_customerBillToXML" />
                <output message="tns:ArWs_customerBillToXMLResponse" />
                </operation>
                - <operation name="customerBillToXMLRowSet">
                <input message="tns:ArWs_customerBillToXMLRowSet" />
                <output message="tns:ArWs_customerBillToXMLRowSetResponse" />
                </operation>
                - <operation name="customerShipToXML">
                <input message="tns:ArWs_customerShipToXML" />
                <output message="tns:ArWs_customerShipToXMLResponse" />
                </operation>
                - <operation name="customerShipToXMLRowSet">
                <input message="tns:ArWs_customerShipToXMLRowSet" />
                <output message="tns:ArWs_customerShipToXMLRowSetResponse" />
                </operation>
                - <operation name="customerXML">
                <input message="tns:ArWs_customerXML" />
                <output message="tns:ArWs_customerXMLResponse" />
                </operation>
                - <operation name="customerXMLRowSet">
                <input message="tns:ArWs_customerXMLRowSet" />
                <output message="tns:ArWs_customerXMLRowSetResponse" />
                </operation>
                - <operation name="salesrepXML">
                <input message="tns:ArWs_salesrepXML" />
                <output message="tns:ArWs_salesrepXMLResponse" />
                </operation>
                - <operation name="salesrepXMLRowSet">
                <input message="tns:ArWs_salesrepXMLRowSet" />
                <output message="tns:ArWs_salesrepXMLRowSetResponse" />
                </operation>
                </portType>
                - <binding name="arWsSoapHttp" type="tns:arWs">
                <soap:binding style="document" transport="http://schemas.xmlsoap.org/soap/http" />
                - <operation name="contactXML">
                <soap:operation soapAction="http://xxas/integration/arws/ArWs.wsdl/contactXML" />
                - <input>
                <soap:body use="literal" />
                </input>
                - <output>
                <soap:body use="literal" parts="result" />
                </output>
                </operation>
                - <operation name="contactXMLRowSet">
                - <input>
                <soap:body use="literal" />
                </input>
                - <output>
                <soap:body use="literal" parts="result" />
                </output>
                </operation>
                - <operation name="customerBillToXML">
                - <input>
                <soap:body use="literal" />
                </input>
                - <output>
                <soap:body use="literal" parts="result" />
                </output>
                </operation>
                - <operation name="customerBillToXMLRowSet">
                - <input>
                <soap:body use="literal" />
                </input>
                - <output>
                <soap:body use="literal" parts="result" />
                </output>
                </operation>
                - <operation name="customerShipToXML">
                - <input>
                <soap:body use="literal" />
                </input>
                - <output>
                <soap:body use="literal" parts="result" />
                </output>
                </operation>
                - <operation name="customerShipToXMLRowSet">
                - <input>
                <soap:body use="literal" />
                </input>
                - <output>
                <soap:body use="literal" parts="result" />
                </output>
                </operation>
                - <operation name="customerXML">
                - <input>
                <soap:body use="literal" />
                </input>
                - <output>
                <soap:body use="literal" parts="result" />
                </output>
                </operation>
                - <operation name="customerXMLRowSet">
                - <input>
                <soap:body use="literal" />
                </input>
                - <output>
                <soap:body use="literal" parts="result" />
                </output>
                </operation>
                - <operation name="salesrepXML">
                - <input>
                <soap:body use="literal" />
                </input>
                - <output>
                <soap:body use="literal" parts="result" />
                </output>
                </operation>
                - <operation name="salesrepXMLRowSet">
                - <input>
                <soap:body use="literal" />
                </input>
                - <output>
                <soap:body use="literal" parts="result" />
                </output>
                </operation>
                </binding>
                - <service name="arWs">
                - <port name="arWsSoapHttpPort" binding="tns:arWsSoapHttp">
                </port>
                </service>
                </definitions>

                • 5. Re: Need Web Service Consumption Assistance
                  JR "Bob" Dobbs-qSBHQ2 Level 3

                  It looks like you're getting an array containing a single Apache Axis MessageElement object.  I'd take a look at the Axis documentation and see if it is helpful.  You might try something like: a_customerXMLResponseElement.get_any()[1].getValue() .  This *might* return the underlying XML as a string.

                   

                  Apache Axis Documentation for org.apache.axis.message.MessageElement class.
                  http://ws.apache.org/axis/java/apiDocs/org/apache/axis/message/MessageElement.html

                   

                  You might also consider posting to and/or searching in the Axis user mailing list.
                  http://ws.apache.org/axis/mail.html

                   

                  Please be aware I'm not a Java or Axis expert, but I hope this helps.

                  • 6. Re: Need Web Service Consumption Assistance
                    fs22 Level 1

                    You have been very helpful. With your assistance, I have discovered that it returns an XML array. I was able to validate that with the IsArray function. Allow me to explain what I am going to do with the result set and let me know if you see any issues with it...

                     

                    I am going to be creating a form where a customer can put in their customer number to submit to a web service. This web service will return the XML array. I will use the code below to convert the array to a list and then use a cfif statement to validate the result set of the list. Based upon that cfif outcome, I can then take action for the end user. Does this soound ok?

                     

                    <cfset test = #ArrayToList(a_customerXMLResponseElement.get_any())#>

                    <cfif #test# CONTAINS "whatever_content_we_test_against">Yes<cfelse>No</cfif>

                     

                    Thanks again.

                    • 7. Re: Need Web Service Consumption Assistance
                      JR "Bob" Dobbs-qSBHQ2 Level 3

                      Glad to have helped.  In regards to your handling of the XML returned from the service; be careful using the ArrayToList function.  A CF list is just a comma delimited string.  If your data contains a comma you could get a list with more items in it then items in the array.  In addition list functions such as ListLen ignore empty elements.  If the XML array you mention is an XML document or contains an XML document you are probably better off using ColdFusion's built in XML functions.

                       

                      Can you provide a sample of an XML array and the content you'd like to check for?

                       

                      XML functions
                      http://livedocs.adobe.com/coldfusion/8/htmldocs/help.html?content=functions-pt0_21.html#34 68770

                       

                      Using XML and WDDX
                      http://livedocs.adobe.com/coldfusion/8/htmldocs/help.html?content=XML_01.html

                      • 8. Re: Need Web Service Consumption Assistance
                        fs22 Level 1

                        Here is the XML that is returned...

                         

                        <result>

                             <ROWSET>

                                  <ROW num="1">

                                       <CUSTOMER_NUMBER>019889</CUSTOMER_NUMBER>

                                       <CUSTOMER>MOUNTAIN BUILDING SUPPLY, INC #8228</CUSTOMER>

                                       <PLATFORM>500</PLATFORM>

                                  </ROW>

                             </ROWSET>

                        </result>

                         

                        What do you recommend?

                        • 9. Re: Need Web Service Consumption Assistance
                          JR "Bob" Dobbs-qSBHQ2 Level 3

                          I'd use Xpath via CF's XMLSearch function to search the result document and pull out the data you need.  See a basic sample below.  If this sample doesn't fit your needs please let me know.

                           

                          For an overview of Xpath see http://msdn.microsoft.com/en-us/library/ms256115.aspx

                           

                           

                           

                          <!--- sample data --->
                          <cfsavecontent variable="serviceResult">
                              <result>
                                   <ROWSET>
                                        <ROW num="1">
                                             <CUSTOMER_NUMBER>019889</CUSTOMER_NUMBER>
                                             <CUSTOMER>MOUNTAIN BUILDING SUPPLY, INC #8228</CUSTOMER>
                                             <PLATFORM>500</PLATFORM>
                                        </ROW>
                                   </ROWSET>
                              </result>
                          </cfsavecontent>

                           

                           

                           

                          <!--- use XML functions to parse and search serivceResult data  --->

                           

                          <!--- we expect the results from the service to be XML, but its always good to check --->
                          <cfif IsXml(serviceResult)>
                             
                              <!--- create an XML object that CF's XML functions can use --->
                              <cfset xmlResult=XmlParse(serviceResult, true) />

                           

                              <!--- check for a customer number of 019889, will return an array of matching objects
                              Note that second parameter for XmlSearch function is an Xpath expresssion
                               --->
                              <cfset customerSearch=XmlSearch(xmlResult, '/result/ROWSET/ROW/CUSTOMER_NUMBER[.="019889"]') />
                              <cfif ArrayLen(customerSearch) gt 0>
                                  Customer found
                              <cfelse>
                                  Customer not found
                              </cfif>
                          </cfif>

                          • 10. Re: Need Web Service Consumption Assistance
                            fs22 Level 1

                            That works perfectly. Thanks a heap! This will help me on several projects I am working on. For example, I have another project where I am attempting to consume a .Net service and have been beating my head against a wall.

                            • 11. Re: Need Web Service Consumption Assistance
                              JR "Bob" Dobbs-qSBHQ2 Level 3

                              The book "Adobe ColdFusion 8 Advanced Application Development" by Ben Forta includes a code sample on converting a .NET web service dataset to a ColdFusion struct.

                              • 12. Re: Need Web Service Consumption Assistance
                                fs22 Level 1

                                I might have to purchase that. UNfortunately, my company is on CF7. I am trying to get them to move forward.