• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

Sending XML formatted text to web service

Contributor ,
Apr 22, 2014 Apr 22, 2014

Copy link to clipboard

Copied

I have a series of forms that send information to various web services.

One is a login form, which consists of a username/password combo, and some other credentials specified in the code.  My CF code looks like this:

<cfinvoke

    webservice="https://my.web.service.url/login?wsdl"

    method="userLookupBySession"

    returnvariable="appauth">

        <cfinvokeargument name="applicationName" value="MYAPP" />

        <cfinvokeargument name="accessCode" value="123456" />

        <cfinvokeargument name="sessionId" value="#session.appid#" />

        <cfinvokeargument name="endUserIPAddress" value="#CGI.REMOTE_ADDR#" />

</cfinvoke>

And that works quite well.

Another form is a registration form.  Like the one above, it accepts four arguments.

  • Application name
  • Access code
  • User data, formatted as XML
  • User's IP address.

Here's my code:

<cfxml variable="userData">

<cfoutput>

<USER xmlns:xsi="_http://www.w3.org/2001/XMLSchema-instance">

    <ROW NUM="1">

        <LOGIN_ID>#htmleditformat(userid)#</LOGIN_ID>

        <PASSWORD>#htmleditformat(FORM.password)#</PASSWORD>

        <NAME_LAST>#htmleditformat(FORM.name_last)#</NAME_LAST>

        <NAME_FIRST>#htmleditformat(FORM.name_first)#</NAME_FIRST>

        <NAME_MI></NAME_MI>

        <EMAIL>#htmleditformat(FORM.email)#</EMAIL>

        <OFFICE_PHONE>#htmleditformat(FORM.office_phone)#</OFFICE_PHONE>

        <OFFICE_EXT>#htmleditformat(FORM.office_ext)#</OFFICE_EXT>

        <OFFICE_FAX></OFFICE_FAX>

        <OFFICE_STREET1>#htmleditformat(FORM.office_street1)#</OFFICE_STREET1>

        <OFFICE_STREET2>#htmleditformat(FORM.office_street2)#</OFFICE_STREET2>

        <OFFICE_CITY>#htmleditformat(FORM.office_city)#</OFFICE_CITY>

        <OFFICE_STATE>#htmleditformat(FORM.office_state)#</OFFICE_STATE>

        <OFFICE_ZIP>#htmleditformat(FORM.office_zip)#</OFFICE_ZIP>

        <ORG_TYPE>#htmleditformat(FORM.org_type)#</ORG_TYPE>

        <ORG_NAME>#htmleditformat(FORM.org_name)#</ORG_NAME>

        <USER_TYPE>J</USER_TYPE>

    </ROW>

</USER>

</cfoutput>

</cfxml>

And:

<cfinvoke

    webservice="https://my.web.service.url/register?wsdl"

    method="registerRequest"

    returnvariable="regged">

        <cfinvokeargument name="applicationName" value="MYAPP" />

        <cfinvokeargument name="accessCode" value="123456" />

        <cfinvokeargument name="userData" value="#userData#" />

        <cfinvokeargument name="endUserIPAddress" value="#CGI.REMOTE_ADDR#" />

</cfinvoke>

For some reason this fails, but if I have one of the server guys use the raw XML data, it works fine, so there's something wrong with my cfinvoke.

Has anyone else passed XML data to a web service?  Is there any special thing you need to do to format it?

Views

6.2K

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Enthusiast ,
Apr 22, 2014 Apr 22, 2014

Copy link to clipboard

Copied

Sometimes there can be a BOM (Byte Order Mark) in the XML that can upset things (see http://stackoverflow.com/questions/6480243/coldfusion-content-not-allowed-in-prolog-xml-with-no-bom for example). Check that and also trim the userData variable to make sure there's no whitespace before the first tag in the XML data.

Can you please cfdump your XML object (userData) and paste it here please? Have you also tried just passing a raw XML payload, rather than using CFXML? Worth a try. I don't use CXXML myself; I generally build the XML string literally and place in the values.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Contributor ,
Apr 22, 2014 Apr 22, 2014

Copy link to clipboard

Copied

I just tried replacing CFXML with cfsavecontent and dumping the XML file right into there (trimmed) but I got the same.

I tried replacing cfinvoke with cfhttp to no avail, although I do get a different error.'

<cfhttp url="https://my.web.service.url/register?wsdl" method="post" result="regged">

    <cfhttpparam type="header" name="SOAPAction" value="""....""" />

    <cfhttpparam type="header" name="applicationName-type" value="MYAPP">

    <cfhttpparam type="header" name="accessCode" value="123456">

    <cfhttpparam type="xml" name="userData" value="#trim(userData)#">

    <cfhttpparam type="header" name="endUserIPAddress" value="#CGI.REMOTE_ADDR#">

</cfhttp>

Error is: org.xml.sax.SAXException: Bad envelope tag: USER

I wonder if this is because I'm not specifying the method like I am in the cfinvoke.

The raw XML (dumped) is:

<USER xmlns:xsi="_http://www.w3.org/2001/XMLSchema-instance">

<ROW NUM="1">

<LOGIN_ID>JDOE</LOGIN_ID>

<PASSWORD>xxxxxxxxx</PASSWORD>

<NAME_LAST>Doe</NAME_LAST>

<NAME_FIRST>John</NAME_FIRST>

<NAME_MI></NAME_MI>

<EMAIL>me@myemail.com</EMAIL>

<OFFICE_PHONE>202-555-1212</OFFICE_PHONE>

<OFFICE_EXT></OFFICE_EXT>

<OFFICE_FAX></OFFICE_FAX>

<OFFICE_STREET1>1200 New Jersey Ave, NE</OFFICE_STREET1>

<OFFICE_STREET2></OFFICE_STREET2>

<OFFICE_CITY>Washington</OFFICE_CITY>

<OFFICE_STATE>DC</OFFICE_STATE>

<OFFICE_ZIP>20590</OFFICE_ZIP>

<ORG_TYPE>Fed</ORG_TYPE>

<ORG_NAME>FHWA</ORG_NAME>

<USER_TYPE>J</USER_TYPE>

</ROW>

</USER>

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Enthusiast ,
Apr 22, 2014 Apr 22, 2014

Copy link to clipboard

Copied

The error (bad envelope) seems to imply it's an endpoint issue and is not the XML itself (which looks ok). Should you be using the WSDL location rather than the resource endpoint location? Time to check the documentation for the API you are using.

This is a good article on SOAP calls in ColdFusion and uses the same syntax for some SOAP calls that we use to various APIs:

http://www.bennadel.com/blog/1809-making-soap-web-service-requests-with-coldfusion-and-cfhttp.htm

Notice how the SOAP envelope has a different XML syntax to what you are using. Perhaps try that syntax?

Also, I'm not sure the:

<cfhttpparam type="header" name="SOAPAction" value="""....""" />

is correct. All of our API/SOAP code has a value provided by the API for the SOAPAction value. Perhaps you should see if you can find one to use from the documentation? Our code also differs in that we have "body" as the the xml parameter name:

<cfhttpparam type="xml" name="body" value="#xmlPayload#">

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Contributor ,
Apr 23, 2014 Apr 23, 2014

Copy link to clipboard

Copied

Funnily enough, I got this: <cfhttpparam type="header" name="SOAPAction" value="""....""" /> from another Ben Nadel post.  I had a missing soapaction header error before adding it, and after I added it the error changed to something else.

My web service is looking for this:

<wsdl:message name="registerRequest">

<wsdl:part name="applicationName" type="soapenc:string"/>

<wsdl:part name="accessCode" type="soapenc:string"/>

<wsdl:part name="userData" type="soapenc:string"/>  (userdada formatted as xml string)

<wsdl:part name="endUserIPAddress" type="soapenc:string"/>

</wsdl:message>

I've always used cfinvoke to call these web services, but with this one I get the following error when I run it:

Web service operation registerRequest with parameters (my params) cannot be found.

which is why I thought about trying the cfhttp method.  But it looks like I have to reformat what I'm sending for that to work.  I'll try to use the Ben Nadel article you posted as a template and see how it goes.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Enthusiast ,
Apr 23, 2014 Apr 23, 2014

Copy link to clipboard

Copied

I try to use as less CF tags as possible for these API calls, build the XML string manually and CFHTTP it. I've never used CFINVOKE. Let us know how it goes.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Contributor ,
Apr 23, 2014 Apr 23, 2014

Copy link to clipboard

Copied

Ok, getting closer!  After reformatting the soap stuff for the cfhttp, I'm getting the error "Incorrect service name."

I have a feeling it's me not correctly specifying what I want in the place where Ben has this:

<Subscriber.AddAndResubscribe xmlns="http://api.createsend.com/api/">

For the xmlns attrib I've used the URL of my web service, but I'm not sure what to use for the first part.  I'm thinking it's some form of this from my web service:

<wsdl:message name="registerRequest">

Any ideas?

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Enthusiast ,
Apr 23, 2014 Apr 23, 2014

Copy link to clipboard

Copied

Can you show the code and please also dump the result. Is the result XML?

The Subscriber.AddAndResubscribe is part of the API (Ben was using the CampaignMonitor API, see: http://campmon.com.au/api/v2/method/subscriber-addandresubscribe/ for examples) and the xmlns looks like the endpoint URL. You need to find the API method that you are trying to call, and insert that perhaps. Is that the "registerRequest" you mentioned?

Does your API have any documentation. Can you private message me it?

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Contributor ,
Apr 23, 2014 Apr 23, 2014

Copy link to clipboard

Copied

The documentation is only a Word document that tells you what params the client will pass. It tells you what to expect from a success, and it gives you a list of failure codes, none of which seem to be passed to ColdFusion.  The web service is normally used by ASP apps on a different server.  I'm the first person in the agency who has successfully gotten the CF web server to talk to the user authentication server.

Here's my code:

<cfsavecontent variable="uData">

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

<Registration.registerRequest xmlns="https://my.webservice.ws?wsdl">

<USER xmlns:xsi="_http://www.w3.org/2001/XMLSchema-instance">

    <ROW NUM="1">

        <LOGIN_ID>#htmleditformat(userid)#</LOGIN_ID>

        <PASSWORD>#htmleditformat(FORM.password)#</PASSWORD>

        <NAME_LAST>#htmleditformat(FORM.name_last)#</NAME_LAST>

        <NAME_FIRST>#htmleditformat(FORM.name_first)#</NAME_FIRST>

        <NAME_MI></NAME_MI>

        <EMAIL>#htmleditformat(FORM.email)#</EMAIL>

        <OFFICE_PHONE>#htmleditformat(FORM.office_phone)#</OFFICE_PHONE>

        <OFFICE_EXT>#htmleditformat(FORM.office_ext)#</OFFICE_EXT>

        <OFFICE_FAX></OFFICE_FAX>

        <OFFICE_STREET1>#htmleditformat(FORM.office_street1)#</OFFICE_STREET1>

        <OFFICE_STREET2>#htmleditformat(FORM.office_street2)#</OFFICE_STREET2>

        <OFFICE_CITY>#htmleditformat(FORM.office_city)#</OFFICE_CITY>

        <OFFICE_STATE>#htmleditformat(FORM.office_state)#</OFFICE_STATE>

        <OFFICE_ZIP>#htmleditformat(FORM.office_zip)#</OFFICE_ZIP>

        <ORG_TYPE>#htmleditformat(FORM.org_type)#</ORG_TYPE>

        <ORG_NAME>#htmleditformat(FORM.org_name)#</ORG_NAME>

        <TPEA_USER_TYPE>J</TPEA_USER_TYPE>

    </ROW>

</USER>

</Registration.registerRequest>

</soap:Body>

</soap:Envelope>

</cfoutput>

</cfsavecontent>

<cfhttp url="https://my.webservice.ws?wsdl" method="post" result="regged">

    <cfhttpparam type="header" name="SOAPAction" value="https://my.webservice.ws?wsdl" /> (still not sure what value is right here)

    <cfhttpparam type="header" name="applicationName-type" value="MYAPP">

    <cfhttpparam type="header" name="accessCode" value="123456">

    <cfhttpparam type="xml" name="userData" value="#trim(uData)#">

    <cfhttpparam type="header" name="endUserIPAddress" value="#CGI.REMOTE_ADDR#">

</cfhttp>

Here's the resulting 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>

<Registration.registerRequest xmlns="https://my.webservice.ws?wsdl">

<USER xmlns:xsi="_http://www.w3.org/2001/XMLSchema-instance">

    <ROW NUM="1">

        <LOGIN_ID>TESTUSER</LOGIN_ID>

        <PASSWORD>xxxxxxx</PASSWORD>

        <NAME_LAST>USER</NAME_LAST>

        <NAME_FIRST>TEST</NAME_FIRST>

        <NAME_MI></NAME_MI>

        <EMAIL>foo@bar.com</EMAIL>

        <OFFICE_PHONE>202-555-1212</OFFICE_PHONE>

        <OFFICE_EXT></OFFICE_EXT>

        <OFFICE_FAX></OFFICE_FAX>

        <OFFICE_STREET1>1200 New Jersey Ave, NE</OFFICE_STREET1>

        <OFFICE_STREET2></OFFICE_STREET2>

        <OFFICE_CITY>Washington</OFFICE_CITY>

        <OFFICE_STATE>DC</OFFICE_STATE>

        <OFFICE_ZIP>20590</OFFICE_ZIP>

        <ORG_TYPE>FHWA</ORG_TYPE>

        <ORG_NAME>FHWA</ORG_NAME>

        <USER_TYPE>J</USER_TYPE>

    </ROW>

</USER>

</Registration.registerRequest>

</soap:Body>

</soap:Envelope>

Keep in mind that I don't know if this XML format is acceptable.  I do know the first version (in post 2) is, because the server guys pasted it in directly and it worked.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Enthusiast ,
Apr 23, 2014 Apr 23, 2014

Copy link to clipboard

Copied

Try posting your XML in point 2 to the endpoint with SOAPAction set to "registerRequest" - it's a method that it's expecting there I think (in our code it's a method name from the API, not a URL). Make sure xml is the last entry too perhaps.

In our code we use "body" as the name of the parameter that passes the XML. Try that too, for example we have this:

<cfhttp url="https://domain.com/ourapi.cfc?wsdl" method="POST" resolveurl="NO">

  <cfhttpparam type="header" name="SOAPAction" value="Addressing">

  <cfhttpparam type="xml" name="body" value="#localscope.soapRequest#">

</cfhttp>

You'll need your extra headers of course if you are authenticating etc.

I will test for you myself, but I'll need the details and the documentation and you'll have to trust me

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Contributor ,
Apr 23, 2014 Apr 23, 2014

Copy link to clipboard

Copied

Success!

I emailed the server guy and asked him about one of my error messages.  He sent me his SOAP request and I saw right away where the differences were.

All the arguments had to be coded in the SOAP request as tags, like this:

<applicationName xsi:type="soapenc:string" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/">MYAPP</applicationName>

<accessCode xsi:type="soapenc:string" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/">123456</accessCode>

<userData xsi:type="soapenc:string" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/">

(xml string)

</userData>

<endUserIPAddress xsi:type="soapenc:string" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/">#CGI.REMOTE_ADDR#</endUserIPAddress>

BAM! It works!

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Enthusiast ,
Apr 23, 2014 Apr 23, 2014

Copy link to clipboard

Copied

Ah yes, the same with us too. We have the authentication details in the tags as well. Wish I'd mentioned it earlier, but it depends on the API. Some want them as tags others can be passed as URL parameters. Glad you got it working - can you show us the code with the pertinent details removed?

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Contributor ,
Apr 23, 2014 Apr 23, 2014

Copy link to clipboard

Copied

This is the working code.  In the example I was sent, the HTML tag brackets were escaped, so I've left it that way.

<cfsavecontent variable="uData">

<cfoutput>

<soapenv:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:web="http://web.ws">

   <soapenv:Header/>

   <soapenv:Body>

      <web:register soapenv:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">

         <applicationName xsi:type="soapenc:string" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/">MYAPP</applicationName>

         <accessCode xsi:type="soapenc:string" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/">123456</accessCode>

         <userData xsi:type="soapenc:string" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/">

                                &lt;USER xmlns:xsi="_http://www.w3.org/2001/XMLSchema-instance"&gt;

                                                &lt;ROW NUM="1"&gt;

                                &lt;LOGIN_ID&gt;#htmleditformat(userid)#&lt;/LOGIN_ID&gt;

                                &lt;PASSWORD&gt;#htmleditformat(FORM.password)#&lt;/PASSWORD&gt;

                                &lt;NAME_LAST&gt;#htmleditformat(FORM.name_last)#&lt;/NAME_LAST&gt;

                                &lt;NAME_FIRST&gt;#htmleditformat(FORM.name_first)#&lt;/NAME_FIRST&gt;

                                &lt;NAME_MI&gt;&lt;/NAME_MI&gt;

                                &lt;EMAIL&gt;#htmleditformat(FORM.email)#&lt;/EMAIL&gt;

                                &lt;OFFICE_PHONE&gt;#htmleditformat(FORM.office_phone)#&lt;/OFFICE_PHONE&gt;

                                &lt;OFFICE_EXT&gt;#htmleditformat(FORM.office_ext)#&lt;/OFFICE_EXT&gt;

                                &lt;OFFICE_FAX&gt;&lt;/OFFICE_FAX&gt;

                                &lt;OFFICE_STREET1&gt;#htmleditformat(FORM.office_street1)#&lt;/OFFICE_STREET1&gt;

                                &lt;OFFICE_STREET2&gt;#htmleditformat(FORM.office_street2)#&lt;/OFFICE_STREET2&gt;

                                &lt;OFFICE_CITY&gt;#htmleditformat(FORM.office_city)#&lt;/OFFICE_CITY&gt;

                                &lt;OFFICE_STATE&gt;#htmleditformat(FORM.office_state)#&lt;/OFFICE_STATE&gt;

                                &lt;OFFICE_ZIP&gt;#htmleditformat(FORM.office_zip)#&lt;/OFFICE_ZIP&gt;

                                &lt;ORG_TYPE&gt;#htmleditformat(FORM.org_type)#&lt;/ORG_TYPE&gt;

                                &lt;ORG_NAME&gt;#htmleditformat(FORM.org_name)#&lt;/ORG_NAME&gt;

                                &lt;TPEA_USER_TYPE&gt;J&lt;/TPEA_USER_TYPE&gt;

                                                &lt;/ROW&gt;

                                &lt;/USER&gt;              

         </userData>

         <endUserIPAddress xsi:type="soapenc:string" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/">#CGI.REMOTE_ADDR#</endUserIPAddress>

      </web:register>

   </soapenv:Body>

</soapenv:Envelope>

</cfoutput>

</cfsavecontent>

<cfhttp url="https://my.webservice.ws/register?wsdl" method="post" result="regged">

    <cfhttpparam type="header" name="SOAPAction" value="registerRequest" />

    <cfhttpparam type="header" name="applicationName-type" value="MYAPP">

    <cfhttpparam type="header" name="accessCode" value="123456">

    <cfhttpparam type="xml" name="userData" value="#trim(uData)#">

    <cfhttpparam type="header" name="endUserIPAddress" value="#CGI.REMOTE_ADDR#">

</cfhttp>

Now I need to figure out how to pull the faultcode out of this SOAP response.  I'm trying to use XMLParse() but it's not working the way it seems to work for your usual XML doc.

<?xml version="1.0" encoding="UTF-8"?>

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">

<soapenv:Body>

<soapenv:Fault>

<faultcode>120</faultcode>

<faultstring>Login ID: PJOHNSON already exists.</faultstring>

<faultactor>register</faultactor>

</soapenv:Fault>

</soapenv:Body>

</soapenv:Envelope>

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Apr 23, 2014 Apr 23, 2014

Copy link to clipboard

Copied

Can you show us the code you are using to get the faultcode from the doc, and what the error is?  Sometimes I've found it helpful to do a replace of "soapenv:" with "" before doing the xmlParse() call.  If you do that, then you should be able to reference the fault info as

yourxmldocname.Fault.faultcode.xmlText

yourxmldocname.Fault.faultstring.xmlText

yourxmldocname.Fault.faultfactor.xmlText

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Contributor ,
Apr 23, 2014 Apr 23, 2014

Copy link to clipboard

Copied

<cfoutput>#regged.Filecontent#"</cfoutput> gives me the XML I pasted above.

So I tried this:

<cfset results = XMLParse(regged.Filecontent)>

<cfset results1 = xmlSearch(results,"faultcode") />

<cfoutput>#results1#</cfoutput>

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Enthusiast ,
Apr 23, 2014 Apr 23, 2014

Copy link to clipboard

Copied

This works for me:

xmlSearch(results, "//soapenv:Fault/faultcode")>

Then results2[1].xmlText yields the value 120.

Test code:

<cfset xml = '<?xml version="1.0" encoding="UTF-8"?>' &
'<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">' &
'<soapenv:Body>' &
'<soapenv:Fault>' &
'<faultcode>120</faultcode>' &
'<faultstring>Login ID: PJOHNSON already exists.</faultstring>' &
'<faultactor>register</faultactor>' &
'</soapenv:Fault>' &
'</soapenv:Body>' &
'</soapenv:Envelope>'>

<cfset results = XMLParse(xml)>
<cfset results2 = xmlSearch(results, "//soapenv:Fault/faultcode")>
<cfdump var="#results2[1].xmlText#">

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Contributor ,
Apr 23, 2014 Apr 23, 2014

Copy link to clipboard

Copied

You're my new favorite person.

That worked.  Now I can just go through all the possible faultcodes and write proper error messages for them.

Thanks!

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Enthusiast ,
Apr 23, 2014 Apr 23, 2014

Copy link to clipboard

Copied

You're welcome   Your API people can probably give you a list of error codes, then you can put them in a table and query them out.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Contributor ,
Apr 24, 2014 Apr 24, 2014

Copy link to clipboard

Copied

LATEST

There are only 4 likely errors (username exists, password too weak, username too short, database error) so I stuck them in a switch block, with a successful reg being the default case.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Resources
Documentation