In my recent CFDJ article on ColdFusion and .NET via Web Services, I wrote about a somewhat ugly way to send CF Queries to .NET. At the time, I struggled with finding a better solution, but couldn't get anything else to work.
I revisited the problem recently, and found that I now seem to be able to get data out of the QueryBean result that'll let me use a CF Query in .NET without performing any sort of transformation on the CF side.
You'll probably still need to perform some .NET-side transformation to get a bindable result, but at least you can now do transformation only if needed.
Without any further ago, here's a sample CFC that returns a query:
<cfcomponent>
<cffunction name="getQuery" access="remote" returnType="query">
<cfset var query = queryNew("Id,Value") />
<cfset var i = "" />
<cfset var j = "" />
<cfloop from="1" to="#randRange(50, 100)#" index="i">
<cfset queryAddRow(query, 1) />
<cfset querySetCell(query, "Id", "Id_" & i, i) />
<cfset querySetCell(query, "Value", "Value_" & i, i) />
</cfloop>
<cfreturn query />
</cffunction>
</cfcomponent>
And a C# client for it (assuming you've built a web reference to the CFC's wsdl in the queryTest namespace):
queryTest.queryServiceService myService = new queryTest.queryServiceService();
queryTest.QueryBean result = myService.getQuery();
Response.Write("Query Results:<br />");
int i;
int j;
for (i=0;i<result.columnList.Length;i++)
{
Response.Write(result.columnList[i] + " ");
}
Response.Write("<br />");
for (i=0;i<result.data.Length;i++)
{
Object[] row = (Object[]) result.data[i];
for (j=0;j<row.Length;j++)
{
Response.Write((string) row[j] + " ");
}
Response.Write("<br />");
}
2 comments - Posted by Joe Rinehart at 8:11 AM - Categories: ColdFusion MX | .NET and ColdFusion