1,105,409 Community Members

Returning a struct through a web service

Member Avatar
cmhampton
Junior Poster in Training
83 posts since Feb 2008
Reputation Points: 8 [?]
Q&As Helped to Solve: 10 [?]
Skill Endorsements: 0 [?]
 
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

Member Avatar
arrgh
Posting Pro in Training
408 posts since Dec 2008
Reputation Points: 22 [?]
Q&As Helped to Solve: 50 [?]
Skill Endorsements: 0 [?]
 
0
 

From the little I've read there are some compatibility issues w/.net and soap. I haven't seen any success stories. Just suggestions to use xml instead.
http://stackoverflow.com/questions/1132536/consuming-apachesoapmap-complex-datatype-in-webservice-using-net

Member Avatar
arrgh
Posting Pro in Training
408 posts since Dec 2008
Reputation Points: 22 [?]
Q&As Helped to Solve: 50 [?]
Skill Endorsements: 0 [?]
 
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

Member Avatar
cmhampton
Junior Poster in Training
83 posts since Feb 2008
Reputation Points: 8 [?]
Q&As Helped to Solve: 10 [?]
Skill Endorsements: 0 [?]
 
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 3 Years Ago by arrgh
Member Avatar
arrgh
Posting Pro in Training
408 posts since Dec 2008
Reputation Points: 22 [?]
Q&As Helped to Solve: 50 [?]
Skill Endorsements: 0 [?]
 
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..

Member Avatar
Ragen
Newbie Poster
1 post since Nov 2010
Reputation Points: 0 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
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