Has anyone ever tried returning a ColdFusion structure through a web service? The WSDL type CF assigns to this is apachesoap:Map, but when I consume this in VB.NET, the data is null.

I have converted the entire thing into a JSON string, and that seems to work, but it requires a ton of code on the .NET side to handle. We are trying to do this with a minimal amount of work for our customers.

Thanks

I've found a "solution". It's not perfect, but it works pretty well. If you use SerializeJSON, it will convert it into a properly formatted JSON string. In this case we are actually returning an array of structures, so instead of serializing the entire object, if you serialize each struct as you append it to the array, it gets returned as a impl:ArrayOf_xsd_anyType SOAP type. .NET has no trouble with this at all. Then there's a couple lines to write in .NET to convert that into objects:

<cfset retArray = ArrayNew(1) />

<cfloop query="queryToProcess">

<cfscript>

tempStruct = StructNew();

StructInsert(tempStruct, "Field1", queryToProcess.field1);
StructInsert(tempStruct, "Field2", queryToProcess.field2);

ArrayAppend(retArray, SerializeJSON(tempStruct));

</cfscript>

</cfloop>
Dim objTemp As Object 'This has to be created as an object instead of an array.
objTemp = WebServiceClass.GetData() 'This would be the web service class created by the Web Reference.

Dim serializer As New JavaScriptSerializer()
Dim theClass As New MyClass()
Dim theCollection As New MyClassCollection() 'These are your class objects
Dim index As Integer = 0

'Loop through each entity in the object
For index = 0 To objTemp.length - 1
theClass = serializer.Deserialize(Of MyClass)(objTemp(index)) 'Deserialize the JSON data
theCollection.Add(theClass) ' Add it to the collection
Next

The important thing here is that the Class created in .NET must have properties named exactly the same as the keys of the structure. Otherwise, they will not map properly.

I hope this helps someone else out there. I searched for hours to find a solution and found many others having the same problem, with no answer.

Thanks for posting it. Too bad there's no way to trade generic objects back and forth without creating a separate class. But at least you found something that works! That's more than I've seen until now..

The solution is simple, but take us some time to find out

if you go to your file wsdl in your Visual Studio, openit and review the code

when u see something like this:

<xsd:element minOccurs="0" name="item" type="apachesoap:mapItem" />

note that I've erased the property unbounded="..." I don't remember
what were here, but if you erase this unbounded and save and run your project
there will be not nulls!!!!!! yeah!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.