I am trying to create my first webservice in coldfusion and i can’t seem to get it to work properly. I am trying to query a database and then with the results but an XML file and return that. When i try to execute the CFM page i get an error saying “Web service operation kyle with parameters {} cannot be found.” I have been trying to figure out how to fix this but have gotten no where. Any help is appreciated. Thanks
This is my cfc file.
<cfcomponent>
<cffunction name="kyle" access="remote" returntype="string" output="no">
<cfset Var namelist = "">
<cfset var getnames = "">
<cfquery name="getnames" datasource="ASC1">
SELECT ID ,FirstName, LastName, Country_of_birth
FROM ASC1.dbo.Kyle
</cfquery>
<cfsavecontent variable="namelist">
<names>
<cfoutput query="getnames">
<name id="#ID#">
<firstname>#XMLFormat(FirstName)#</firstname>
<lastname>#XMLFormat(LastName)#</lastname>
<Country_of_birth>#XMLFormat(Country_of_birth)#</Country_of_birth>
</name>
</cfoutput>
</names>
</cfsavecontent>
<cfreturn namelist>
</cffunction>
</cfcomponent>
This is my cfm page
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>
<cfinvoke method="kyle" returnvariable="rawXMLnamelist" webservice="http://180.302.204.10/KyleCF/Webservice/kyle.cfc?wsdl">
</cfinvoke>
<cfset list = XmlParse(rawXMLnamelist)>
<cfdump var="#list#">
<body>
</body>
</html>
Looks fine.
Based on the error message, I’d check that the path to the cfc is correct. If you go directly to http://180.302.204.10/KyleCF/Webservice/kyle.cfc does it come up or do you get a page not found error?
I still haven’t been able to get kyle.cfc?wsdl to work. I created a new one and embedded the xml into the cfc. At one point i had this webservice working but for some reason it does not work now; when i try to invoke it i get an error message saying:
The XML page cannot be displayed
Cannot view XML input using XSL style sheet. Please correct the error and then click the Refresh button, or try again later.
Only one top level element is allowed in an XML document. Error processing resource 'http://180.302.204.10/KyleCF/Webservice…
<h2>DUMP</h2>
–^
Does anyone know what would cause this issue? I have heard that this issue will appear if there is an error with IIS is that true?
thanks for the help
<cfcomponent>
<cfsavecontent variable="XMLFile"><?xml version="1.0"?>
<names>
<name>
<firstname>Kyle</firstname>
<lastname>Beaulieu</lastname>
</name>
<name>
<firstname>elyK</firstname>
<lastname>ueiluaeB</lastname>
</name>
</names>
</cfsavecontent>
<cfset MyXMLDoc = xmlParse(XMLFile) />
<h2>DUMP</h2>
<cfdump var="#MyXMLDoc#">
<cfset NameNodes = xmlSearch(MyXMLDoc, '/names/name')>
<cfoutput>
<h2>Name Nodes</h2>
<cfloop from="1" to="#arraylen(NameNodes)#" index="i">
<cfset NameXML = xmlparse(NameNodes[i]) />
<b>First Name:</b>#NameXML.name.firstname.xmltext#<br>
<b>Last Name: </b>#NameXML.name.lastname.xmltext#<br>
</cfloop>
</cfoutput>
</cfcomponent>
I don’t have time to look closely now, but the key is
Only one top level element is allowed in an XML document.
If you can look at the resulting XML you should be able to figure out where things are going wrong.