Hi,
How do I make a web method to return an object class MyClass, also how do I
make it to return List<MyClass>?
TIA
Marc Gravell - 25 Mar 2008 06:19 GMT
If you mean an asmx-style web-service, then something like below - but
note that the remote proxy won't get the exact same class
representation but a lightweight data abstraction (and quite likely a
MyClass[] at the caller). With WCF it is possible to use either the
proxy approach, or via assembly-sharing you can use the exact same
class.
Marc
[Serializable]
public class MyClass {...}
[WebMethod]
public MyClass Foo(...) {...}
[WebMethod]
public List<MyClass> Bar(...) {...}
Arne Vajhøj - 29 Mar 2008 20:23 GMT
> How do I make a web method to return an object class MyClass, also how do I
> make it to return List<MyClass>?
Returning a MyClass is straigth forward. Make sure that MyClass
is following proper paradigms about private fields and public
properties.
You should not return a List<MyClass> from a web service but
instead a MyClass[], because List is .NET specific.
(I believe that List<MyClass> will be exposed as MyClass[], so
it will work, but be a bit confusing)
Arne