Re: Stumped - Strongly Typed Arrays question (with simplified code example)

Tech-Archive recommends: Fix windows errors by optimizing your registry

From: Chris Taylor (chris_taylor_za_at_hotmail.com)
Date: 03/24/04


Date: Thu, 25 Mar 2004 01:51:37 +0200

Hi,

Webservices do not share type, they share descriptions. So while you have a
.NET class on the server called ItemHolder, the webservice does not share
this actual type, it shares the fact that there is a definition that
contains an array of items and these items have a string inside them. The
reason for this is that webservices are intended to be consumed from
heterogeneous clients. The sharing of platform specific types like
CollectionBase would negate that possibility since these are pretty much
.NET specific.
To share complex datatypes you would have to resort to .NET Remoting.

Hope this helps

-- 
Chris Taylor
http://dotnetjunkies.com/WebLog/chris.taylor/
"JH" <jason.hunt@noticeablydifferent.com> wrote in message
news:a06bd62c.0403241447.21072b9a@posting.google.com...
> Hello All,
>   I am looking for guidance on this issue. I am certain it is not new,
> but I haven't been able to find a solution that seems to fit right, so
> any leads to resources or other information would be greatly
> appreciated.
>
>   If you have a class object, exposed by a remoting service, that
> encapsulates a private member with a strongly-typed custom array (that
> implements CollectionBase) type, the remoting service passes the
> strongly typed array as a System.Array, thus not enabling access to
> other IList methods such as Add or Remove.
>
>   When done without a web service, the accessor method for the
> collection in the encapsulating class can access the IList methods
> (such as Add) directly directly, using the format
> "ItemHolder.Items.Add( new Item() );". With the web service, the array
> comes across as a strongly-typed array (e.g. Item[]), but that does
> not give you the ability to use Add and the like from IList
> (implemented in the custom strongly-typed array, exposed by the web
> service). Casting the System.Array to an IList still does not give you
> the ability to add the item and results in an exception, "Collection
> was of a fixed size.", being thrown.
>
>   If you have any suggestions they would be welcomed and greatly
> appreciated.
>
> Sincerely,
> JH
>
> e.g.
> //---------- Web Service Side ----------//
> //Simple type, exposed by the Web Service
> public class Item
> {
>   private string name;
>   public Item(){}
>   public string Name
>   {
>     get{ return name;}
>     set{ name = value;}
>   }
> }
>
> // Strongly typed collection, exposed by the Web Service
> public class ItemCollection : CollectionBase
> {
>   public ActivitySetList(){}
>   public int Add( Item item )
>   {
>     return List.Add( item );
>   }
>   public void Insert( int index, Item item )
>   {
>     List.Insert( index, item );
>   }
>   public void Remove( Item item )
>   {
>     List.Remove( item );
>   }
>   public bool Contains( Item item )
>   {
>     return List.Contains( item );
>   }
>   public int IndexOf( Item item )
>   {
>     return List.IndexOf( item );
>   }
>   public void CopyTo( Item[] itemArray, int index )
>   {
>     List.CopyTo( itemArray, index );
>   }
>   public Item this[ int index ]
>   {
>     get { return ( Item )List[ index ]; }
>     set { List[ index ] = value; }
>   }
> }
>
> //Encapsulating type, exposed by the web service
> public class ItemHolder
> {
>   private ItemCollection itemCollection = new ItemCollection();
>   public ItemHolder(){}
>   public ItemCollection Items
>   {
>     get{ return itemCollection; }
>   }
> }
>
> // Webservice methods
> [WebMethod]
> public ItemHolder CreateItemHolder()
> {
>   return new ItemHolder();
> }
> [WedMethod]
> public Item CreateNewItem()
> {
>   return new Item();
> }
>
> //---------- Client Side ----------//
> // Sample client code
> IList _itemHolder = <WebReferenceName>.CreateItemHolder();
> // The following line throws the
> //"Colleciton was of a fixed size" exception
> ((IList)_itemHolder.Items).Add( <WebReferenceName>.CreateItem() );


Relevant Pages

  • Stumped - Strongly Typed Arrays question (with simplified code example)
    ... encapsulates a private member with a strongly-typed custom array (that ... When done without a web service, ... public class ItemCollection: CollectionBase ... public void CopyTo(ItemitemArray, int index) ...
    (microsoft.public.dotnet.framework.aspnet.webservices)
  • Stumped - Strongly Typed Arrays question (with simplified code example)
    ... encapsulates a private member with a strongly-typed custom array (that ... When done without a web service, ... public class ItemCollection: CollectionBase ... public void CopyTo(ItemitemArray, int index) ...
    (microsoft.public.dotnet.framework.webservices)
  • RE: Consuming Web Services
    ... with proxies, you just grab wsdl adn xsd files from your webservices, and ... BizTalk and your webservice, that the key advantage of webservices. ... >> I'm creating an internal web service that biztalk is going to call. ...
    (microsoft.public.biztalk.server)
  • Re: What should I do webapp or webservice + webapp?
    ... WebServices are good for nonpropietary data transfer. ... If you only have dotnet apps, ... A web service for UPS makes sense, because anybody can talk to it. ... BusinessLogicLayer ...
    (microsoft.public.dotnet.framework.aspnet)
  • Re: Webservices (Vs) .cs class files
    ... there is no additional overhead with your approach. ... when you add a web reference to your project, it create a new class file ... that is a proxy for the web service. ... | We are currently using Webservices as normal classes. ...
    (microsoft.public.dotnet.framework.aspnet)