Last posts:
Web Design » Web Development » CF Queries in .NET via Web Services: A Better Approach
CF Queries in .NET via Web Services: A Better Approach
Views: 1896 | 12-11-2010, 08:21 | Category : Web Development

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 />");
}


Tags: ColdFusion MX, .NET and ColdFusion



Read also:
  • CFCUnit + FlexUnit How-To: No excuses now!
  • What's with variables-dot-underscore in my CFC's?
  • I Don't Like Rails
  • More CF + .NET Craziness
  • C++ Development services

  • Vote
    What do you need?

    Website design
    Website development
    PHP Tutorials
    Other


    Hire Desk
    »
    Website Design & Development, Php Tutorials
    This is Web developer Blog TheDesignMag
    Only high quality web developming service