returning strongly typed dataset from web service

N

N. Shehzad

All,
I have a webservice webmethod which does returns a strongly typed dataset
called MyStronglyTypedDataSet correctly.

On the client side, when I cast the dataset to my strongly typed dataset, it
throws the following error "Cannot convert type
ClientConsumer.localhost.MyStronglyTypedDataSet" to
"MyNameSpace.WebServices.MyStronglyTypedDataSet'

If I cast it as a regular dataset on client side, it works fine, but that
defeats the whole purpose of having strongly typed DS in first place.

I am using a web reference from the client application to the web service,
and also reference to the StronglyTpedDataSet dll that I created using SDK
Command Prompt

What am I doing wrong?
 
J

John Saunders

N. Shehzad said:
All,
I have a webservice webmethod which does returns a strongly typed dataset
called MyStronglyTypedDataSet correctly.

On the client side, when I cast the dataset to my strongly typed dataset,
it
throws the following error "Cannot convert type
ClientConsumer.localhost.MyStronglyTypedDataSet" to
"MyNameSpace.WebServices.MyStronglyTypedDataSet'

If I cast it as a regular dataset on client side, it works fine, but that
defeats the whole purpose of having strongly typed DS in first place.

I am using a web reference from the client application to the web service,
and also reference to the StronglyTpedDataSet dll that I created using SDK
Command Prompt

What am I doing wrong?

Why are you referencing the dll from the server? The client and server
classes have no direct relation to each other.

What happens if you create a new project and use Add Web Reference to add a
reference to your web service? Isn't that enough to get you your
strongly-typed dataset on the client side?

John

P.S. I just tried it myself, and it seems to work. Just keep in mind that
you've got a server-side DataSet and a client-side proxy DataSet, and that
the two types are unrelated.
 
S

Scott M.

Why are you trying to cast an object into the type that it already is? You
don't need to cast at all here.

Your client code should simply be:

Dim receivedDataSet As MyStronglyTypedDataSet = webService.webMethodCall()

If your web method is returing a type of "MyStronglyTypedDataSet", all you
need to do is set up a pointer (not a new instance) to that returned object.
That pionter needs to be declared as being the same type (or a type that
your returned object derives from).

Now, having said all of this. IMHO you shouldn't be returning a platform
specific object from a web service in the first place. That defeats the
purpose of a web service. I would recommend returning the XML
representation of the strongly typed DataSet from your web service, rather
than the object itself. This keeps your application open to the possibility
of needing a heterogenius architecture in the future.
 
S

Sundar Narasiman

N. Shehzad,

The main reason for the problem is that you are bundling the TypedDataset
into an class library (dll). Please do not package the TypedDataset into an
assembly.
If you do that, you will end-up in the namespace conflicts.
Try using the .xsd for TypedDataset at the
Webservice side and the Client Side. I've used .xsd (instead of bundling .xsd
inside assembly), it works. I could able to successfully pass the
TypedDataset back-and-forth between webservice and client.

Please let me know if this helps
 
N

N. Shehzad

Hi Sundar,
I did create an .xsd schema first, and created a class file for that xsd
schema using
SDK Command prompt. How would I reference that class on the client side if I
do not create a .dll library. Do I need to include that class on the client
project as well?

Thanks
 
J

John Saunders

N. Shehzad said:
Hi Sundar,
I did create an .xsd schema first, and created a class file for that xsd
schema using
SDK Command prompt. How would I reference that class on the client side if
I
do not create a .dll library. Do I need to include that class on the
client
project as well?

You don't need to do _anything_ to reference the class on the client side.
Simply define your web service to return the strongly-typed dataset. Then
use Add Web Reference in your client application to cause VS.NET to create
the necessary proxy classes. One of those classes will be a client-side
version of the server-side dataset. You will use that class on the client
side.

You will _never_ reference server-side classes on the client side. NEVER.

John
 
N

N. Shehzad

John,
The problem is it does not create those client proxy classes for the dataset.
When I add the web reference, it only creates the localhost reference that's
all
 
J

John Saunders

N. Shehzad said:
John,
The problem is it does not create those client proxy classes for the
dataset.
When I add the web reference, it only creates the localhost reference
that's
all

Select the "localhost" reference in Solution Explorer. Turn on "Show All
Files", either by clicking the icon at the top of the Solution Explorer, or
else using Project->Show All Files. This will add a "+" sign in front of
"localhost". Click the plus signs a few times, and you'll find a
Reference.cs (or .vb) file. Open that, and you should see all of the proxy
classes.

OTOH, which version of VS.NET are you using? This may be a VS2005 feature.

John
 
N

N. Shehzad

Actually, I got it to work with one dataset, but if my webservice has
multiple typed datasets, they do not show up as proxy xsd when I create or
update the web reference.
 
J

John Saunders

N. Shehzad said:
Actually, I got it to work with one dataset, but if my webservice has
multiple typed datasets, they do not show up as proxy xsd when I create or
update the web reference.

See my other post, and which version of VS.NET are you using?

John
 
N

N. Shehzad

I am using vs 2005. It seems like vs 2005 only creates proxy xsd class for
only one strongly typed dataset. if the webservice is using multiple
datasets, it does not create multiple classes how can I make the reference
map to reflect both classes?
 
J

John Saunders

N. Shehzad said:
I am using vs 2005. It seems like vs 2005 only creates proxy xsd class for
only one strongly typed dataset. if the webservice is using multiple
datasets, it does not create multiple classes how can I make the reference
map to reflect both classes?

Are both datasets used as return values?

As an experiment, try changing the return type of the method whose dataset
is being created in the proxy class with one of those that is not:

Now a proxy for class A is being created:

[WebMethod]
A Method1(){return new A();}

[WebMethod]
B Method2(){return new B();}


Change it to this and see what happens:

[WebMethod]
B Method1(){return new B();}

[WebMethod]
A Method2(){return new A();}

John
 
S

Scott M.

This is completely incorrect.

A Typed DataSet is NOT an XSD. These are two different things.

A Typed DataSet is a class that inherits from the DataSet class and has
custom properties and methods created for it that model your specific data.
This is a class and there is NO POSSIBLE WAY to not have it be part of an
assembly (or a namespace for that matter).

An XSD is an XML Schema Document, which is simply an XML Schema model of
your empty DataSet.

I have already provided the source and solution of your problem in my first
reply.
 
S

Scott M.

This is not correct.

When you reference a web service, a proxy class for the web service is
created on the web service consumer. BUT, proxies for all possible
webMethod return types are NOT created.

If the client will be receiving a strongly-typed DataSet, then the client
will need this class referenced directly. This can be accomplished by the
strongly-typed DataSet existing in a separate assembly that both the web
service and it's consumer can both reference separately, or a copy of the
class exists in another place for the client to reference.
 
S

Scott M.

No John, only the web service class gets a proxy created for it. Not the
return types of the web method calls.
 
S

Scott M.

XSD's can't be proxies as XSD's aren't classes. You are confusing Schemas
with typed dataSets.
 
J

John Saunders

Scott M. said:
This is not correct.

When you reference a web service, a proxy class for the web service is
created on the web service consumer. BUT, proxies for all possible
webMethod return types are NOT created.

If the client will be receiving a strongly-typed DataSet, then the client
will need this class referenced directly. This can be accomplished by the
strongly-typed DataSet existing in a separate assembly that both the web
service and it's consumer can both reference separately, or a copy of the
class exists in another place for the client to reference.

Sorry, I don't know where you get this from. Maybe you're talking about .NET
1.1?

Of course proxies are created for the WebMethod return types. How do you
expect a client to be able to access them?

I think you're confusing Web Services and Remoting. In the case of Remoting,
you_do_ share the data types.

John
 
J

John Saunders

Scott M. said:
No John, only the web service class gets a proxy created for it. Not the
return types of the web method calls.

Sorry, man, you need to go check your facts. Create an example and see what
happens. I did, and it behaves as I posted.

My only question (which I'll check when I get a chance) is what happens when
there's more than one typed dataset involved. One of the posters said that
only one proxy is generated, and since my example only used one typed
dataset, I can't tell if he's correct or not.

John
 
J

John Saunders

Scott M. said:
XSD's can't be proxies as XSD's aren't classes. You are confusing Schemas
with typed dataSets.

Scott, have you noticed any .xsd files associated with strongly-typed
DataSets? Do you have strongly-typed datasets in your projects which do NOT
have an .XSD file nearby?

John
 
S

Scott M.

They are related, but they are not one in the same. Have you noticed that
you can delete either the typed dataset or the XSD and continue to use
whichever remains?

XSD's are not a MS invention, they are the W3C standard schema mechanism. A
typed DataSet is a .NET class that is modeled after your data structure, an
XSD is an XML Schema that is modeled after your data.

They can work together, but they are not the same thing. An XSD is not
defined in the .NET Framework. A DataSet is. An XSD is not a class (and so
you can't have a proxy class for something that isn't a class in the first
place), a typed DataSet is.
 

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

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top