Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Collection Data Type changed to array when returning from Webservice

Status
Not open for further replies.

NeilTrain

Programmer
May 27, 2003
275
US
I have a webservice, one method, "GetSites()", returns an object of type "SiteCollection" which is a collection of "SiteDefinition" objects (derived from CollectionBase). The webservice compiles ok, but when I try to compile the app that consumes this webservice, I get the error:

Cannot implicitly convert type 'SiteDefinition[]' to 'SiteCollection'

Why is it being reported as a SiteDefinition array? I have tried right cliking on the web reference and clicking "update service" and also removing and re-adding the service, neither of which fix the problem.
 
Collection types are not supported by the SOAP specification, but arrays are.

This is because SOAP is intended to be cross-platform, and passing a .NET arraylist object to a Java webservice wouldn't make sense.

In the same light, make sure that any objects you pass to a webservice are "simple" types -- integers, strings, etc.

Chip H.


____________________________________________________________________
Donate to Katrina relief:
If you want to get the best response to a question, please read FAQ222-2244 first
 
Chip, thats what I figured, But I was a little confused that instead of throwing up an error along the lines of "you can't return a Collection", it went behind my back (little bastard) and converted my collection to an array.

But I can live with that, so I modified my consumer to expect data in an array instead, which leads to another problem.

I use this code in the consumer:
Code:
SiteDefinition[] sd = myWebService.GetSites();
so that both the return type, and the type I am populating, are arrays of SiteDefinitions.

Which then gives me this error:
Cannot implicitly convert type 'myNameSpace.myWebService.SiteDefinition[]' to 'myNameSpace.SiteDefinition[]'

My "SiteDefinition" object is simply a group of 6 strings (SiteName, URL, etc) Should I just transfer the whole object as XML and forget this auto generated SOAP stuff?
 
I wouldn't try and use strongly-typed collections or arrays across a SOAP connection at all.

But it you really want to, you can manually edit the generated .cs file it produces for you to make it use your types, or expose the generated types so the rest of your program can use it.

Chip H.


____________________________________________________________________
Donate to Katrina relief:
If you want to get the best response to a question, please read FAQ222-2244 first
 
Ya I think I will stay away from using anything but simple types in SOAP. My collection already has functions to save/load itself to/from a file on disk using XML, so I'm just gonna pass the XML across the SOAP connection.

Thanks for your help
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top