I have created a custom collection class by extending CollectionBase.
For Example.
[Serializable()]
Public Class SomeObject
{
int i;
string s;
}
[Serializable()]
Public Class SomeObjectCollection :
System.Collections.CollectionBase
{
public SomeObjectCollection ()
{}
public virtual void Add(SomeObject NewObject)
{
this.List.Add (NewObject);
}
public virtual void Remove(SomeObject oObject)
{
this.List.Remove(oObject);
}
public virtual SomeObject this[int index]
{
get
{
return (SomeObject) this.List[index];
}
set
{
this.List[index] = value;
}
}
}
One of my web methods returns SomeObjectCollection. But when i call
this web service from another application it returns an array of
SomeObject instead of SomeObjectCollection. Is there any way for the
client to get the SomeObjectCollection instead of an array? Thanks for
your help.
Hi Ratish,
This is the expected behavior. From a "on the wire" perspective, a
collection and an array look identical, since all that the description
contains is that a repeating element can occur at a given location. The
WSDL.exe tooling that is behind the client-side proxy code generation step
always creates an array, and does not infer a typed collection.
If you want to have your caller see the collection, you'll have to alter
the generated proxy, and share the implementation of your collection and
private type in an assembly. Do this in two steps. First, add a reference
to the assembly (add reference) in your calling application. Then open the
generated proxy, comment out the definitions for the proxy types, change
the method signature to recognize your collection class, and add an
[Imports] statement at the top of the file, referencing the .NET namespace
for the assembly that contains your classes.
I hope this helps
Dan Rogers
Microsoft Corporation
--------------------
>From: "Ratish" <ratish.bhaskaran@gmail.com>
>Newsgroups: microsoft.public.dotnet.framework.aspnet.webservices
[quoted text clipped - 8 lines]
>Content-Type: text/plain; charset="iso-8859-1"
>X-Trace: posting.google.com 1102016167 29759 127.0.0.1 (2 Dec 2004
19:36:07 GMT)
>X-Complaints-To: groups-abuse@google.com
>NNTP-Posting-Date: Thu, 2 Dec 2004 19:36:07 +0000 (UTC)
[quoted text clipped - 3 lines]
> posting-account=V6azlQ0AAAC_j9uQhEjTNqNQkESoxHBI
>Path:
cpmsftngxa10.phx.gbl!TK2MSFTFEED02.phx.gbl!tornado.fastwebnet.it!tiscali!new
sfeed1.ip.tiscali.net!proxad.net!216.239.36.134.MISMATCH!postnews.google.com
!c13g2000cwb.googlegroups.com!not-for-mail
>Xref: cpmsftngxa10.phx.gbl
microsoft.public.dotnet.framework.aspnet.webservices:26998
>X-Tomcat-NG: microsoft.public.dotnet.framework.aspnet.webservices
>
[quoted text clipped - 42 lines]
>client to get the SomeObjectCollection instead of an array? Thanks for
>your help.
Ratish - 04 Dec 2004 16:29 GMT
Thanks for the info. But the problem is I am using a dynamic proxy
generator to generate the proxy at runtime from the wsdl. Is there any
way around it?
> Hi Ratish,
>
[quoted text clipped - 39 lines]
> > posting-account=V6azlQ0AAAC_j9uQhEjTNqNQkESoxHBI
> >Path:
cpmsftngxa10.phx.gbl!TK2MSFTFEED02.phx.gbl!tornado.fastwebnet.it!tiscali!new
sfeed1.ip.tiscali.net!proxad.net!216.239.36.134.MISMATCH!postnews.google.com
> !c13g2000cwb.googlegroups.com!not-for-mail
> >Xref: cpmsftngxa10.phx.gbl
[quoted text clipped - 45 lines]
> >client to get the SomeObjectCollection instead of an array? Thanks for
> >your help.
Dan Rogers - 06 Dec 2004 20:32 GMT
Hi Ratish,
Yes, you can create a dynamic proxy generator that provides the programming
interface you desire. Right now, if you are calling a proxy generator such
as XSD.exe, it doesn't provide the programming model you are looking for.
You can do what I did and create your own proxy generator - and thus
provide yourself with whatever client-side programming model you like.
Alternately, I have heard that there are some commercial proxy generators
that have a run-time license that may be of interest. Also, if you want a
"collections" style experience, and if you are already generating the proxy
by scripting out to XSD.exe, you might be able to call out to XsdObjectGen
from your own program, as it is already a managed object with a code
generation interface exposed.
I hope this helps
Dan Rogers
Microsoft Corporation
--------------------
>From: "Ratish" <ratish.bhaskaran@gmail.com>
>Newsgroups: microsoft.public.dotnet.framework.aspnet.webservices
[quoted text clipped - 10 lines]
>Content-Type: text/plain; charset="iso-8859-1"
>X-Trace: posting.google.com 1102177781 11590 127.0.0.1 (4 Dec 2004
16:29:41 GMT)
>X-Complaints-To: groups-abuse@google.com
>NNTP-Posting-Date: Sat, 4 Dec 2004 16:29:41 +0000 (UTC)
[quoted text clipped - 4 lines]
> posting-account=V6azlQ0AAAC_j9uQhEjTNqNQkESoxHBI
>Path:
cpmsftngxa10.phx.gbl!TK2MSFTNGXA01.phx.gbl!TK2MSFTFEED02.phx.gbl!tornado.fas
twebnet.it!tiscali!newsfeed1.ip.tiscali.net!news.glorb.com!postnews.google.c
om!z14g2000cwz.googlegroups.com!not-for-mail
>Xref: cpmsftngxa10.phx.gbl
microsoft.public.dotnet.framework.aspnet.webservices:27036
>X-Tomcat-NG: microsoft.public.dotnet.framework.aspnet.webservices
>
[quoted text clipped - 110 lines]
>for
>> >your help.