C# – Making an ASP.NET ASMX web service easily callable by ColdFusion web clients

ccoldfusionweb services

I've written an ASP.NET webservice (.asmx style rather than WCF) and I have the main web methods working now in my prototype enviroment. Now I need to add several new parameters to one of the webmethods but, more significantly, I need to make my webservice as "consumable" (callable) as possible from a ColdFusion web application. I'm confused about how to best design parameter types for the webservice methods in light of usage by CF (or other client callers).

My prototype relies on my own ASP.NET web page which calls my webservice; here is how the proxy class for my service is called from the .aspx page:

BrokerASMXProxy.Svc.FileService brokerService = new BrokerASMXProxy.Svc.FileService();
recNumber = brokerService.UploadFile(binData, fileNameOnly, kvData);

Here is the signature of the webmethod:

[WebMethod]
    public string UploadFile(byte[] incomingArray
        , string FileName
        , MetaData[] metaDataArray)

I'm a little concerned already about the byte array and the MetaData array (will ColdFusion have a problem calling this service with argument types like that?). I assume strings are not a problem but what are the best practices for designing webmethods (and their types) for use by ALL types of callers?

p.s. I also have a DownloadFile webmethod that has "out" parameters:

    [WebMethod]
    public bool DownloadFile(string recNumString, out byte[] docContents, out string returnFiletype)

..and I wonder similarly about ColdFusion's accomodation of these outputs. Thank you in advance.

Best Answer

If you're running ColdFusion 8, and happen to have that on the same physical server as your .NET code, you may be better off using .NET integration, where you can write a .NET class and intantiate it inside your CF code as if it were a CFC or a Java object.

Here's a good example (with tons more on the same blog) of writing a .NET class that's used in CFML code.

However, if your .NET and CF app servers are not on the same machine, you may have to go with a web service as you originally thought.

The great thing about web services is that they are language agnostic. It looks like you have a MetaData type or class defined, and you're expecting a collection of those to be sent as an input parameter. What that's going to ultimately translate to is some XML that represents that array, and each item in the array will be broken down to its core parts (strings, numbers, bools, etc)... In theory, it should just work, as long as you design your input XML accordingly.

It's been a while since I last created a .NET web service, but I'm sure there's a way to look at the expected XML structure (aka WSDL). Find that, and you've got your answer. Then you just need to create XML that fits that definition from your ColdFusion code and you're all set.

Related Topic