Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Help with Webservices and XML

Status
Not open for further replies.

johne417

Programmer
Sep 18, 2001
23
US
I'm doing a webservices call and having some troubles.

Here's the code in my cfc:
<cfcomponent
displayName=&quot;Detail of an Individual Account&quot;
hint=&quot;Returns the detail of a single individual account&quot; >

<cffunction
name=&quot;IndividualAccountDetail&quot;
output=&quot;false&quot;
access=&quot;remote&quot;
displayname=&quot;Detail of an Individual Account&quot;
hint=&quot;Returns the detail of a single individual account&quot;
returntype=&quot;string&quot;>

<cfxml variable=&quot;IndividualAccounts&quot;>
<IndividualAccounts>
<firstname>John</firstname>
<lastname>Smith</lastname>
<IndividualAccounts>

<cfset unParsedXML=&quot;#IndividualAccounts#&quot;>
<cfreturn unParsedXML>

</cffunction>
</cfcomponent>

----------------------------------------------------------

In my base page I call the CFC from
here's the relevant code:

<cfinvoke webservice=&quot;#application.siteurl#/WebServices/IndividualAccountDetail.cfc?WSDL&quot;>
returnvariable=&quot;userDetail&quot;
method=&quot;IndividualAccountDetail&quot; >
</cfinvoke>

<cfset temp=xmlParse(userDetail)>
<cfdump var=&quot;#temp#&quot;>

------------------------------------
I get the following error:
Document root not found

If I comment out the xmlparse(userdetail) line, the cfdump returns 'coldfusion.xml.XmlNodeList@2daf89'.

I have no idea why I'm getting that error? Is my XML invalid or something?

Thanks in advance for any help.

 
OOPs, I just noticed that while retyping in the post box I missed the / in my close Individual Accounts tag in the XML. It's there in my real code though, problem still there.
 
Do you have a close tag for your
Code:
CFXML
, though?

Code:
<cfxml variable=&quot;IndividualAccounts&quot;>
<IndividualAccounts>
  <firstname>John</firstname>
  <lastname>Smith</lastname>
</IndividualAccounts>
Code:
</cfxml>
Code:


-Carl
 
Also, check out the comments at the bottom of the LiveDocs for CFXML:

Since you're writing a CFC, I assume you're using
Code:
<cfsetting enablecfoutputonly=&quot;yes&quot; ...>
somewhere. So you'd need to wrap the entire document definition in CFOUTPUTs:
Code:
<CFXML variable=&quot;IndividualAccounts&quot;>
<CFOUTPUT>
<IndividualAccounts>
  <firstname>John</firstname>
  <lastname>Smith</lastname>
</IndividualAccounts>
</CFOUTPUT>
</CFXML>
in order for anything to be saved to the IndividualAccounts variable.


-Carl
 
Thanks for the reply Carl.

I did have my </cfxml> in production as well. Gotta be more careful retyping stuff...

And I don't have a <cfsetting enablecfoutputonly=&quot;yes&quot; ..> in the cfc either.

Strange thing is, when I do a IsXMLDoc on the IndividualAccounts variable in the cfc, I get a &quot;Yes&quot;.
Pass it to the userDetail variable in the calling page, do a IsXMLDoc on it there (without doing anything else to it), and I get 'No'.
 
Ahhh... sure... that's all you needed to say. ;-)

Your CFFUNCTION is saying it's returning a string (which is what you're expecting for the XMLParse)... but what you're actually returning is an XML doc... which is represented in ColdFusion as a structure, though a CFC won't understand it as such.

Trying assembling a true string, rather than an XML doc. You should be able to do this fairly easily by substituting CFSAVECONTENT where your CFXML tags are:
Code:
<cfcomponent
  displayName=&quot;Detail of an Individual Account&quot;
  hint=&quot;Returns the detail of a single individual account&quot; >

<cffunction
  name=&quot;IndividualAccountDetail&quot;
  output=&quot;false&quot;
  access=&quot;remote&quot;
  displayname=&quot;Detail of an Individual Account&quot;
  hint=&quot;Returns the detail of a single individual account&quot;
  returntype=&quot;string&quot;>

<CFSAVECONTENT variable=&quot;IndividualAccounts&quot;>
<IndividualAccounts>
  <firstname>John</firstname>
  <lastname>Smith</lastname>
</IndividualAccounts>
</CFSAVECONTENT>

<cfset unParsedXML=&quot;#IndividualAccounts#&quot;>
<cfreturn unParsedXML>

</cffunction>
</cfcomponent>

and the base page stays exactly how you had it ( except, get rid of that pesky &quot;>&quot; after the webservice attribute, if it's really there ) -

Code:
<cfinvoke webservice=&quot;#application.siteurl#/WebServices/IndividualAccountDetail.cfc?WSDL&quot;
  returnvariable=&quot;userDetail&quot;
  method=&quot;IndividualAccountDetail&quot;>
</cfinvoke>

<cfset temp=xmlParse(userDetail)>
<cfdump var=&quot;#temp#&quot;>

that should do it for you.



-Carl
 
Ah, you were right Carl, the calling page didn't like the structure, and it took a string just fine. I ended up just doin a toString() on the variable and returning that instead of doing the <cfsavecontent>, but I'd guess it works pretty much the same. Thanks a lot for the help.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top