1.11M Members

Returning a struct through a web service

 
0
 

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

 
0
 

Found one article suggesting you return objects instead. I haven't tried it. Let us know if it works.
http://coldfusion.sys-con.com/node/47199

 
0
 

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.

Question Answered as of 4 Years Ago by arrgh
 
0
 

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..

 
0
 

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!

You
This question has already been solved: Start a new discussion instead
Post:
Start New Discussion
Tags Related to this Article