Skip to main content
Known Participant
September 7, 2011
Question

CFC to return a .net dataset

  • September 7, 2011
  • 2 replies
  • 1165 views

Good Morning,

I have a cfc that will be consumed by a .net application. Another company created the .net app, and will not change anything with it, so I have been tasked with creating a cfc that will return a .net dataset.  I'm not even sure what a .net dataset looks like, or if anything in coldfusion will translate into it. Has anyone ever tried to do something like this?

    This topic has been closed for replies.

    2 replies

    Inspiring
    September 9, 2011

    .NET data sets are not returned directly by Web services. Serialized

    versions can be returned, which basically means you return XML with a

    certain markup, then in the .NET code consuming the Web service you

    use the ReadXml function to turn the XML back into a data set object,

    or a similar object like a data table. If you want to, you can look up

    the XML syntax and create a ColdFusion function that generates this

    XML. Alternatively, if you have SQL Server, you can use a .NET library

    or an SSIS package to create the XML using the native .NET WriteXml

    function, then pass that XML to ColdFusion.

    DataSet.WriteXml function:

    http://msdn.microsoft.com/en-us/library/zx8h06sz(v=VS.100).aspx

    Most Web service code that returns large amounts of data these days,

    even in .NET Web sites, uses JSON. You should explore whether JSON is

    an acceptable alternative.

    -Mike Chabot

    Owainnorth
    Inspiring
    September 7, 2011

    I'm not fantastic with .NET and webservices aren't my speciality, so I'm willing to be corrected - but I'm pretty sure you're doomed.

    Webservices are only interoperable as long as you use standard types - strings, numbers, xml etc. Behind the scenes when doing a .NET-.NET webservice call, it actually serialises your objects first then deserialises them again at the other end. The actual format is, I believe, a bespoke .NET protocol which only it understands.

    ColdFusion can not return a .NET DataSet, because it doesn't know how to serialise it. The *only* chance would be:

    1) If the remote application would accept a DataSet which had been serialised into XML or JSON, which I'm pretty sure it won't be default

    2) You could use the .NET System.Xml.Serialization objects to serialise the DataSet within CF, then return it as XML, or JSON.

    But I suspect it simply won't work. If it's not a simple datatype, it's not possible to communicate it between platforms, end of.

    cputnam14Author
    Known Participant
    September 7, 2011

    That is pretty much what I am affraid of.

    Inspiring
    September 9, 2011

    It is possible, but not easy, as stated by Owain North, you will not be able to use the built in web service feature of CF.  You will need to create the XML content of the service request and the HTTP post code by hand.  You might look at chatper 74 of Ben Forta's book "Adobe ColdFusion Advanced Application Development, volume 3".  He has some code sample that converts a .NET data set to a CFQUERY result object.  This might help you convert a CFQUERY result set to a .NET data set.

    You will probably need to use CFHTTP to invoke the .NET web service since I suspect that CF's built in web service feature won't know what to do with your .NET data set object.  Ben Nadel's blog has a sample of using CFHTTP to invoke a web service: http://www.bennadel.com/blog/1809-Making-SOAP-Web-Service-Requests-With-ColdFusion-And-CFHTTP.htm

    I recommend that you request that the ASP.NET team provide you with the autogenerated documentation page for the web service.  This can help you understand what HTTP post requests to the server should look like.  There is an example on the blog post I recommended by Ben Nadel.