Question

I'm pretty sure you can, but in addition to answering the question in the title, could you also explain the pros, cons, caveats, if any, to doing so? I know that you can't return a List, Set, Collection, Map, or any interface, from a WebMethod (which is stupid, IMO, but I don't know what the design reasons were should I should probably withhold judgment).

Thanks for any advice.

-- LES

Was it helpful?

Solution

You can return arrays, and I have found them useful.

The main reason that collections are a problem is that some languages, such as C, doesn't understand the concept of a collection, so, to remain portable you need to make certain to pass structures that can be represented in the majority of languages.

Besides,I am never a fan of passing collections, as, what comes from the webservice should be fairly static. If you want to add to it, then convert the array to a collection, then pass back an array to the webservice to make changes.

OTHER TIPS

James is correct, you can return arrays. You can also return Collection types. The wsdl will define the type as being a list. However, most clients will convert the type into an array (at least that is what I have found C# did with a JAX-WS service).

I used a 3rd party (Apache Axis2) to generate the web service and I came across an odd issue where the wsdl was not being correctly read and the array could not be deserialized correctly by the consumer. It was necessary to create a decorator object, which only contained the array object and have that be returned from the webmethod.

I think that this was just Axis2 not playing well with the .NET web service interpereter, but something to be aware of.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top