Hello
How can you directly expose a Java or .NET type in a CF webservice? My idea is
to expose a Java or .NET enum type thus you have this enumeration exposed in
the WSDL which then consumers can use.
Unfortunately ColdFusion whether knows enumerations nor named constants (which
you could use in a datatype to simulate an enum).
Kind regards and thank you for your help
nummsa - 27 Aug 2007 21:57 GMT
If I'm reading this right ---
Just write a "wrapper" cffunction that invokes the Java or .NET function/class
in question, then "expose" it by setting the access="remote" attribute in the
cffunction tag. What it really comes down to is building a wrapper function for
it.
Parker Lewis - 28 Aug 2007 07:25 GMT
Thanks a lot for your answer. That's exactly what I'd like to do. Could you
tell me what I have to specify in the "returntype" attribute of the cffunction
in order to get a WSDL which precisely returns that .NET or Java type?
Thank you for help
Kind regards
Res Nuessle - 28 Aug 2007 08:29 GMT
Have fun! ;)
<!--- File: webservice.cfc --->
<cfcomponent>
<cffunction name="myFunction" returntype="myVarType" access="remote"
output="false">
<cfobject component="myVarType" name="myVar">
<cfset myVar.a=1>
<cfset myVar.b=2>
<cfreturn myVar>
</cffunction>
</cfcomponent>
<!--- myVarType.cfc (same directory like webservice.cfc) --->
<cfcomponent>
<cfproperty name="a" type="numeric">
<cfproperty name="b" type="numeric">
</cfcomponent>
<!--- testws.cfm ---
<cfinvoke
webservice="h t t p://foo.bar.com/webservice.cfc?wsdl"
method="myFunction"
returnvariable="ret"
>
</cfinvoke>
<cfdump var="#ret#">
<cfdump var="#ret.getB()#">
Parker Lewis - 28 Aug 2007 08:45 GMT
Hmmm, but now you are exposing the cfcomponent "myVarType" which isn't whether
a .NET type nor a Java type. Here is a little example: I'd like to expose the
.NET enum type "DayOfWeek" in a webservice. "DayOfWeek" has to be exposed in
the WSDL. How can I do that?
<cfscript>
myDotNetEnumType = CreateObject(".NET", "System.DayOfWeek");
</cfscript>
<cfdump var="#myDotNetEnumType#" />
Kind regards
tomj - 06 Sep 2007 20:53 GMT
Parker,
You can not do what you want to do. And you shouldn't be able to. :-)
Web services are generally used for interop between (often very different)
systems, tying a service to a particular type goes against that purpose.
For an enumeration, you should just take a string argument and validate that
input in the service for the values you accept ("monday", tuesday", ..). This
is much more in the spirit of web services.
Hope that helps.