ASP.NET 2005 Web Service Design

Nate Bross

Contributor
Joined
Apr 6, 2005
Messages
601
Location
Chicago, IL
I'm just wondering what the best practice for Web Service design is. For example, lets say I am creating an RSS Reader.

If I were creating a Class Library (dll) project, I would have two classes.
1) A class to download and process RSS XML feeds.
2) A Data class to hold all the data (Title, Description, OriginalURL, etc)

Now the first class would have a method like GetRSS(String URL) and it would return an array of the data class (arraylist, collection or something along these lines); however, with a Web Service I cannot return an arraylist of User Defined Objects, so what is the best practice?

Secondly, what is the best organization of code in a 2005 Web Service, and how do I reference it in my client application?

For example, I have these two classes above, so that creates two *.asmx files, with two separate .cs files in the App_Code directory. In the client, do I make a reference to both .asmx files?

Thanks in advance!
 
Add a parameterless constructor

however, with a Web Service I cannot return an arraylist of User Defined Objects

I have never had a problem returning arrays of my own classes from a web service. The only constraint I have come across is that the class must have a parameterless constructor (for serialization).

Good luck :)
 
Yes, as a work around I have been able to use an Array, but I was unable to use an ArrayList, or a Strongly Typed Collection, which inherits from CollectionBase.

As a side question, in a Class Library, if I have an object with an override string ToString() method, if I set the Datasource property of a listbox to an Strongly Typed Collection, it calls my ToString method, however, with a Web Service, my ToString method is overlooked, and the text that shows up in the list box is something like "ProgramName.Namespace.ClassName" instead of what should have been returned by the ToString(). Is this a feature of webservices or am I doing something incorrectly?
 
The .ToString implementation for you custom types isn't available to the client, web services don't allow your types to have a full implementation at the client side simply because there is no guarantee what the client is.
 
Is there another way to emulate this functionality, without rewriting the code inside the Web Service?

Also, if I need to have more than 1 class in a web service, should I have multiple .asmx files and multipal .cs files in the App_Code. Then in the client, just reference ALL of the .asmx files individually? is there a way to group them all into one Web Reference for the Client?
 
Last edited:
Back
Top