Copy link to clipboard
Copied
Hi!
I'm trying to create a web service in ColdFusion 9 that returns a complex structure or has a complex argument. I am placing the .cfc file that describes the structure in the same directory as the .cfc that is using the structure. RIght now I'm just trying to get a wsdl.
I currently have two functions in my .cfc, The first one returns a string. The second one ideally returns an array of strings. Saying returntype="string[]" gives an error that ColdFusion could not parse string
So I tried making a defined type with the individual element being a string:
<cfcomponent>
<cfproperty name="InfoSource" type="string">
<cfcomponent>
------------------------------------
My code that uses this cfc is:
<cfcomponent>
<cffunction name="getzips" access="remote" returntype="string">
<cfset #resultsCommaDelimtedZips# = "this is the result">
<cfreturn CommaDelimitedZips>
</cffunction>
<cffunction name="getInfoSources" access="remote" returntype="InfoSources[]">
</cffunction>
</cfcomponent>
The error that I get is:
AXIS error
Sorry, something seems to have gone wrong... here are the details:
Fault - Error attempting to create Java skeleton for CFC web service.; nested exception is:
coldfusion.xml.rpc.CFCInvocationException: [coldfusion.compiler.ParseException : Invalid CFML construct found on line 3 at column 1.ColdFusion was looking at the following text:<p><</p><p>The CFML compiler was processing:<ul>< marks the beginning of a ColdFusion tag.Did you mean LT or LTE?</ul>]
AxisFault
faultCode: {http://schemas.xmlsoap.org/soap/envelope/}Server.generalException
faultSubcode:
faultString: Error attempting to create Java skeleton for CFC web service.; nested exception is:
coldfusion.xml.rpc.CFCInvocationException: [coldfusion.compiler.ParseException : Invalid CFML construct found on line 3 at column 1.ColdFusion was looking at the following text:<p><</p><p>The CFML compiler was processing:<ul>< marks the beginning of a ColdFusion tag.Did you mean LT or LTE?</ul>]
faultActor:
faultNode:
faultDetail:
{http://xml.apache.org/axis/}hostname:ntc15
----------------------------
I have a similar problem if I use cfproperty:
<cfcomponent>
<cfproperty name="approved" type="string">
<cfproperty name="total_charged" type="string">
<cfproperty name="charge_error" type="string">
<cfproperty name="renewed_until" type="string">
<cfproperty name="reason" type="string">
<cfcomponent>
http://livedocs.adobe.com/coldfusion/8/htmldocs/help.html?content=webservices_20.html says
Note: If the component files are not in a directory under your web root, you must create a web server mapping to the directory that contains them. You cannot use ColdFusion mappings to access web services.
So I tried putting the .cfc file in a directory beneath my wwwroot folder rather than in it. That didn't help.
Any suggestions? I feel like I've done exactly what all the documentation I can find tells me to do!
Thanks!
-- Mabel 🙂
We're working with another company that is doing the front end and using the web service, so I have to have the wsdl show the actual data type, not just "any", which is what using "array" does.
If I use your code (adding a name for the echoStatus argument), I get
<wsdl:part name="getInfoSourcesReturn" type="impl:ArrayOf_xsd_anyType"/>
How do I tell it an array of _strings_ specifically?
ColdFusion is weakly-typed, so I wonder whether one can be so specific in the data type, without resorting t
...Copy link to clipboard
Copied
Looking at this:
<cfcomponent>
<cffunction name="getzips" access="remote" returntype="string">
<cfset #resultsCommaDelimtedZips# = "this is the result">
<cfreturn CommaDelimitedZips>
</cffunction>
Right off the bat I see what are probably undefined variables in your cfset and cfreturn tags.
Copy link to clipboard
Copied
Hi Dan,
Yes that's true. However, ColdFusion is pretty happy dealing with undefined variables in terms of not throwing errors when it encounters one. (You may get a really crazy _result_! So I don't think that has anything to do with why I could get a WSDL. BKBK's code basically works and produces a WSDL, so I'm on the right track now.
Thanks!
-- Mabel 🙂
Copy link to clipboard
Copied
1) Store the component
<cfcomponent>
<cfproperty name="approved" type="string">
<cfproperty name="total_charged" type="string">
<cfproperty name="charge_error" type="string">
<cfproperty name="renewed_until" type="string">
<cfproperty name="reason" type="string">
</cfcomponent>
as Status.cfc
2) Use returntype="array" instead of returntype="InfoSources[]"
3) Define your webservice, say, TestService.cfc, like this:
<cfcomponent>
<cffunction name="getzips" access="remote" returntype="string">
<cfset resultsCommaDelimtedZips = "this is the result">
<cfreturn resultsCommaDelimtedZips>
</cffunction>
<cffunction name="getInfoSources" access="remote" returntype="array">
<cfset var infoSources = arraynew(1)>
<cfset infoSources[1] = "a">
<cfset infoSources[2] = "b">
<cfset infoSources[3] = "c">
<cfreturn infoSources>
</cffunction>
<cffunction name="echoStatus" access="remote" returnType="status" >
<cfargument name="" type="status">
<cfreturn arguments.inputStatus>
</cffunction>
</cfcomponent>
Copy link to clipboard
Copied
Hi BKBK,
Thanks for that input. We're working with another company that is doing the front end and using the web service, so I have to have the wsdl show the actual data type, not just "any", which is what using "array" does.
If I use your code (adding a name for the echoStatus argument), I get
<wsdl:part name="getInfoSourcesReturn" type="impl:ArrayOf_xsd_anyType"/>
How do I tell it an array of _strings_ specifically?
One other question - was that missing name supposed to be inputStatus? (I was trying to figure out why returning an unnamed variable would work, and I think I just figured it out.)
Thanks!
-- Mabel 🙂
Copy link to clipboard
Copied
One other question - was that missing name supposed to be inputStatus?
Yes, that was a typing mistake.
Copy link to clipboard
Copied
We're working with another company that is doing the front end and using the web service, so I have to have the wsdl show the actual data type, not just "any", which is what using "array" does.
If I use your code (adding a name for the echoStatus argument), I get
<wsdl:part name="getInfoSourcesReturn" type="impl:ArrayOf_xsd_anyType"/>
How do I tell it an array of _strings_ specifically?
ColdFusion is weakly-typed, so I wonder whether one can be so specific in the data type, without resorting to Java for example. But then again, you will soon run into all kinds of complications. A ColdFusion array and a java array are 2 entirely different things. Run the following code and you will see why
<cfset testArray = arrayNew(1)>
<cfoutput>#testArray.getClass().getName()#</cfoutput>
in any case, since strings are is a subset of the 'any' type, your service also covers the case where an array of strings is returned.
Copy link to clipboard
Copied
Hi BKBK,
Thanks for your answers! I think I'm set for now.
-- Mabel 🙂