views:

218

answers:

4

Hi,

I am a .NET developer with no coldfusion experience, but I need to write cf code to access a wcf service i've set up. I've got a few WCF services being hosted in IIS 7 with WsHttpBinding, and I'm able to use the services fine by adding service references to a .NET client and using client classes.

It is very straightforward for a .NET developer:

var addressClient = new Service.AddressClient();
addressClient.AddressDTO[] addresses = addressClient.GetAddresses();

It's clear that visual studio does a lot behind the scenes to set up these client classes from the WSDL.

I've seen coldfusion examples using cfinvoke to call web services, but none where they actually set up client classes from the WSDL and create them from the web service response.

So, how is something like this done from coldfusion?

Thanks in advance!

+1  A: 

Adobe actually has a very good reference detailing all the steps necessary to go from WSDL to ColdFusion code to consume a Web Service:

ColdFusion MX: Consuming Web Services

If you're using the WsHttpBinding in WCF, then your Web Service should work just like the one in the example (you can compare your WSDL to the example WSDL to get a feel for how to create everything by hand).

Justin Niessner
A: 

The problem with CF is that is does not do a good job of allowing you to deal with complex objects. So as long as the service is only expecting params of strings and such your OK, but if it wants a complicated nesting of objects it falls apart.

Basically you have to get down to the Axis Java objects.

I answered this once before here:

http://stackoverflow.com/questions/1758143/web-service-is-expecting-a-dataset-object-how-can-i-provide-that-via-coldfusion/1758333#1758333

ryber
A: 

You have to configure an endpoint to act as a .NET webservice. Once you do that you can call it just by using Createobject in coldfusion. Here's a quick example:

<cfscript> 
  wcf = CreateObject("webservice","http://ws.spreety.com/TvOnline2009.svc?wsdl"); 
  variables.TalkShowImgHtml = wcf.GetGenreTalkShowImg("[email protected]"); 
</cfscript> 
<cfoutput>#variables.TalkShowImgHtml#</cfoutput>
Stefano DiFabio
+1  A: 

others are correct in that if your webservice is returning simple data types, cf will map them to cf data types and everything is easy. in some cases though you'll have to covert the complex data types to cf data types yourself.

cflib.org has some function to handle these, so you might want to look there. here is a function to convert a .net dataset being returned from a webservice to a cf query. hopefully this will give you an ah-ha moment:

http://www.cflib.org/index.cfm?event=page.udfbyid&amp;udfid=1580

rip747