Collections in Webservices.

R

Ratish

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.
 
D

Dan Rogers

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" <[email protected]>
Newsgroups: microsoft.public.dotnet.framework.aspnet.webservices
Subject: Collections in Webservices.
Followup-To: microsoft.public.dotnet.framework.aspnet.webservices
Date: 2 Dec 2004 11:36:03 -0800
Organization: http://groups.google.com
Lines: 45
Message-ID: <[email protected]>
NNTP-Posting-Host: 65.241.51.2
Mime-Version: 1.0
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: (e-mail address removed)
NNTP-Posting-Date: Thu, 2 Dec 2004 19:36:07 +0000 (UTC)
User-Agent: G2/0.2
Complaints-To: (e-mail address removed)
Injection-Info: c13g2000cwb.googlegroups.com; posting-host=65.241.51.2;
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

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.
 
R

Ratish

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?



Dan said:
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" <[email protected]>
Newsgroups: microsoft.public.dotnet.framework.aspnet.webservices
Subject: Collections in Webservices.
Followup-To: microsoft.public.dotnet.framework.aspnet.webservices
Date: 2 Dec 2004 11:36:03 -0800
Organization: http://groups.google.com
Lines: 45
Message-ID: <[email protected]>
NNTP-Posting-Host: 65.241.51.2
Mime-Version: 1.0
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: (e-mail address removed)
NNTP-Posting-Date: Thu, 2 Dec 2004 19:36:07 +0000 (UTC)
User-Agent: G2/0.2
Complaints-To: (e-mail address removed)
Injection-Info: c13g2000cwb.googlegroups.com; posting-host=65.241.51.2;
posting-account=V6azlQ0AAAC_j9uQhEjTNqNQkESoxHBI
Path:
cpmsftngxa10.phx.gbl!TK2MSFTFEED02.phx.gbl!tornado.fastwebnet.it!tiscali!newsfeed1.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

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.
 
D

Dan Rogers

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" <[email protected]>
Newsgroups: microsoft.public.dotnet.framework.aspnet.webservices
Subject: Re: Collections in Webservices.
Followup-To: microsoft.public.dotnet.framework.aspnet.webservices
Date: 4 Dec 2004 08:29:35 -0800
Organization: http://groups.google.com
Lines: 118
Message-ID: <[email protected]>
References: <[email protected]>
<[email protected]>
NNTP-Posting-Host: 24.30.87.31
Mime-Version: 1.0
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: (e-mail address removed)
NNTP-Posting-Date: Sat, 4 Dec 2004 16:29:41 +0000 (UTC)
In-Reply-To: <[email protected]>
User-Agent: G2/0.2
Complaints-To: (e-mail address removed)
Injection-Info: z14g2000cwz.googlegroups.com; posting-host=24.30.87.31;
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

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?



Dan said:
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" <[email protected]>
Newsgroups: microsoft.public.dotnet.framework.aspnet.webservices
Subject: Collections in Webservices.
Followup-To: microsoft.public.dotnet.framework.aspnet.webservices
Date: 2 Dec 2004 11:36:03 -0800
Organization: http://groups.google.com
Lines: 45
Message-ID: <[email protected]>
NNTP-Posting-Host: 65.241.51.2
Mime-Version: 1.0
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: (e-mail address removed)
NNTP-Posting-Date: Thu, 2 Dec 2004 19:36:07 +0000 (UTC)
User-Agent: G2/0.2
Complaints-To: (e-mail address removed)
Injection-Info: c13g2000cwb.googlegroups.com; posting-host=65.241.51.2;
posting-account=V6azlQ0AAAC_j9uQhEjTNqNQkESoxHBI
Path:
cpmsftngxa10.phx.gbl!TK2MSFTFEED02.phx.gbl!tornado.fastwebnet.it!tiscali!ne wsfeed1.ip.tiscali.net!proxad.net!216.239.36.134.MISMATCH!postnews.google.co m
!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

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,997
Messages
2,570,239
Members
46,827
Latest member
DMUK_Beginner

Latest Threads

Top