passing structs (setializable) object in web service

S

Stacy Meir

i have tried all possible ways and have failed to pass a serializable struct.
i have three projects: server, client and common. common project contains
struct mydatapacket marked serializable. i use common project reference in
other two projects (client and server).

in client project when i create web reference to server project it imports a
new type from server project something like
server.mywebreference.mydatapacket, which is different from
common.mydatapacket. how do stop this from happening. or, am i completly off
track.

all examples i see pass basic data types and most "complex" pass data sets.
can someone explain or point me to a resource that discusses in detail
passing of compound data structures in web services (hopefully without much
soaping and more c# attributing)

thanks
 
E

erymuzuan

It's true, but you can always manually edit your webreference file, and
replace the object from the WSDL.exe generated with one from your common
project, just make sure you have the XMLNamespace is correct. BTW i'll
always suggest that you use remoting instead. as you have the control of
both the client and the server.


Regards
Erymuzuan Mustapa
Christoph said:
Stacy,

The behavior you're describing is a known "weakness" in v1.x of .NET.
Add Web Reference has no way to recognize types that are in the project
where you are adding the reference to. Furthermore, it doesn't even
re-use proxy classes for XML Schema types referenced from multiple web
services.

In .NET 2.0 you will be able to customize the generation of proxy
classes much better. For now you have to follow the approach outlined
Scott Sealy's article [0].

HTH,
Christoph Schittko
MVP XML
http://weblogs.asp.net/cschittko

[0]
http://msdn.microsoft.com/library/en-us/dnservice/html/service07162002.a
sp?frame=true

-----Original Message-----
From: Stacy Meir [mailto:Stacy (e-mail address removed)]
Posted At: Saturday, January 01, 2005 2:41 AM
Posted To: microsoft.public.dotnet.framework.aspnet.webservices
Conversation: passing structs (setializable) object in web service
Subject: passing structs (setializable) object in web service

i have tried all possible ways and have failed to pass a serializable
struct.
i have three projects: server, client and common. common project
contains

struct mydatapacket marked serializable. i use common project

reference in
other two projects (client and server).

in client project when i create web reference to server project it
imports

a
new type from server project something like
server.mywebreference.mydatapacket, which is different from
common.mydatapacket. how do stop this from happening. or, am i
completly

off
track.

all examples i see pass basic data types and most "complex" pass data
sets.
can someone explain or point me to a resource that discusses in detail
passing of compound data structures in web services (hopefully without
much
soaping and more c# attributing)

thanks
 
S

Stacy Meir

christoph and erymuzuan,

thanks you for replying so quickly.

i did try erymuzuan's approach before but was reluctant for the same reasons
christoph pointed out. during development process i do change my server
frequently and very likely to forget to make manual edit.

christoph, thank you for pointing me in the right direction. to complecate
things further, i do like erymuzuan's point about .net remoting and that
having total control over both client and server types. i am not an expert in
web services yet (may be some day) and would like to know if serialized types
exposed through web services can also export or map methods on the client
side? in other words, is there a way to provide methods available to the
client? i think it will be clear in the example below what i am asking.

on the server:

[Serializable]
public class Person
{
public string Name;
public DateTime DOB;
public TimeSpan Age { get { DateTime.Now-DOS; } }
}

on client when web referenced:

[Serializable]
public class Person
{
public string Name;
public DateTime DOB;
}

now i have lost all of my support methods that really make this object
useful. so this is what i am doing:

[Serializable]
public class wsPerson // transport "flying" object
{
public string Name;
public DateTime Age;
}

is used in server and web referenced in client (which looks/feels the
same... no methods). now i have common.dll that implements Person uses
wsPerson:

public class Person
{
public Person(wsPerson netflyer) { ... copy values ... }
public static explicit operator wsPerson(Person local) { ... copy
attrs .. }

public TimeSpan Age { get { DateTime.Now - Age; } } // me likey
}

i am using transport object to create my "useful" object on the client as
well as server. i am doing this for 50 such objects. is there a better way?
my guess that there should be. thanks again.

regards



Christoph Schittko said:
Scott's article does describe editing the code generated from the web
reference, but generally I strongly discourage people from editing
auto-generated code.

The use of remoting is strongly discouraged [0] at this point with
respect to future interoperability issues and a programming model that
tempts developers to develop strongly coupled systems based on the
distributed object metaphor. Personally, I like the .NET Remoting
framework, and I am somewhat disappointed to see such a fine framework
go away, but knowing the issues ahead I can no longer recommend building
new distributed systems on .NET Remoting. At this point .NET Remoting
should strictly be used for intra-process/cross app domain scenarios.

HTH,
Christoph Schittko
MVP XML
http://weblogs.asp.net/cschittko

[0] http://weblogs.asp.net/cschittko/archive/2004/05/27/143388.aspx

-----Original Message-----
From: erymuzuan [mailto:[email protected]]
Posted At: Sunday, January 02, 2005 7:04 PM
Posted To: microsoft.public.dotnet.framework.aspnet.webservices
Conversation: passing structs (setializable) object in web service
Subject: Re: passing structs (setializable) object in web service

It's true, but you can always manually edit your webreference file, and
replace the object from the WSDL.exe generated with one from your common
project, just make sure you have the XMLNamespace is correct. BTW i'll
always suggest that you use remoting instead. as you have the control of
both the client and the server.


Regards
Erymuzuan Mustapa
Christoph said:
Stacy,

The behavior you're describing is a known "weakness" in v1.x of ..NET.
Add Web Reference has no way to recognize types that are in the project
where you are adding the reference to. Furthermore, it doesn't even
re-use proxy classes for XML Schema types referenced from multiple web
services.

In .NET 2.0 you will be able to customize the generation of proxy
classes much better. For now you have to follow the approach outlined
Scott Sealy's article [0].

HTH,
Christoph Schittko
MVP XML
http://weblogs.asp.net/cschittko

[0]
http://msdn.microsoft.com/library/en-us/dnservice/html/service07162002.a
sp?frame=true


-----Original Message-----
From: Stacy Meir [mailto:Stacy (e-mail address removed)]
Posted At: Saturday, January 01, 2005 2:41 AM
Posted To: microsoft.public.dotnet.framework.aspnet.webservices
Conversation: passing structs (setializable) object in web service
Subject: passing structs (setializable) object in web service

i have tried all possible ways and have failed to pass a serializable
struct.
i have three projects: server, client and common. common project

contains

struct mydatapacket marked serializable. i use common project

reference in

other two projects (client and server).

in client project when i create web reference to server project it

imports

a
new type from server project something like
server.mywebreference.mydatapacket, which is different from
common.mydatapacket. how do stop this from happening. or, am i

completly

off
track.

all examples i see pass basic data types and most "complex" pass data
sets.
can someone explain or point me to a resource that discusses in detail
passing of compound data structures in web services (hopefully without
much
soaping and more c# attributing)

thanks
 
D

Dino Chiesa [Microsoft]

The philosophy of webservices is different than that of remoting .

Webservices is a message-passing model, where a sender sends a message to a
receiver. In the common case, the sender is a client, the receiver a
service, and the messages are passed in request+reply pairs. In your case
the wsPerson is an instance of a Data Transfer Object, which is a common
pattern in these sorts of apps. The DTO is documented in Martin Fowler's
PEAA, #401.
Remoting is a different model. The metaphor is invocation of methods on
remote objects, along with the ability to transport objects (including data
and behavior) between apps. Of course these differences can be either
hidden or encapsulated, so that you can treat both as simple communications
mechanisms. But in my view, they lend themselves to different solutions.

Just with the info you gave in your posts, If I were designing your app, I
would use shared classes to implement the behavior that is shared in both
clients and servers. And I would use a DTO for transmission of state
between clients and servers (in either direction). In .NET these two
things can be the same - in other words a shared domain class (something
that exposes data and methods) can also act implicitly as a DTO (which
exposes data only), via XML Serialization and Webservices. If you want to
be explicit about it, you could define a simple subclass, eg public class
PersonDTO: Person {}. This would be more of a documentation aid than
anything else, because the PersonDTO would still expose all the public
methods from Person. If you want to be more explicit , you could define a
completely separate DTO type with support in Person that would translate
between the two types. Something like what you have done in your example.

Also, for today, to share classes across sender and receiver, you have to
follow Seely's advice as Christoph pointed out earlier - you have to modify
the code generated by wsdl.exe.

By the way #1. I don't agree that modifying generated code is taboo. Any
tool that generates code, including wsdl.exe, is just a tool. If you like
what it generates, use it as is. If you don't like it, you can hand-author
your own code, or you can start with the generated code and customize it.
There's nothing wrong with this. Automatically modifying the generated code
is also ok in my book - using perl or sed or awk or xslt or whatever.

By the way #2: there is a related pattern in Fowler's PEAA, #388, Remote
Facades.

Finally, Web services and Xml Serialization is not affected by the
[Serializable] attribute.

-D


Stacy Meir said:
christoph and erymuzuan,

thanks you for replying so quickly.

i did try erymuzuan's approach before but was reluctant for the same
reasons
christoph pointed out. during development process i do change my server
frequently and very likely to forget to make manual edit.

christoph, thank you for pointing me in the right direction. to complecate
things further, i do like erymuzuan's point about .net remoting and that
having total control over both client and server types. i am not an expert
in
web services yet (may be some day) and would like to know if serialized
types
exposed through web services can also export or map methods on the client
side? in other words, is there a way to provide methods available to the
client? i think it will be clear in the example below what i am asking.

on the server:

[Serializable]
public class Person
{
public string Name;
public DateTime DOB;
public TimeSpan Age { get { DateTime.Now-DOS; } }
}

on client when web referenced:

[Serializable]
public class Person
{
public string Name;
public DateTime DOB;
}

now i have lost all of my support methods that really make this object
useful. so this is what i am doing:

[Serializable]
public class wsPerson // transport "flying" object
{
public string Name;
public DateTime Age;
}

is used in server and web referenced in client (which looks/feels the
same... no methods). now i have common.dll that implements Person uses
wsPerson:

public class Person
{
public Person(wsPerson netflyer) { ... copy values ... }
public static explicit operator wsPerson(Person local) { ... copy
attrs .. }

public TimeSpan Age { get { DateTime.Now - Age; } } // me likey
}

i am using transport object to create my "useful" object on the client as
well as server. i am doing this for 50 such objects. is there a better
way?
my guess that there should be. thanks again.

regards



Christoph Schittko said:
Scott's article does describe editing the code generated from the web
reference, but generally I strongly discourage people from editing
auto-generated code.

The use of remoting is strongly discouraged [0] at this point with
respect to future interoperability issues and a programming model that
tempts developers to develop strongly coupled systems based on the
distributed object metaphor. Personally, I like the .NET Remoting
framework, and I am somewhat disappointed to see such a fine framework
go away, but knowing the issues ahead I can no longer recommend building
new distributed systems on .NET Remoting. At this point .NET Remoting
should strictly be used for intra-process/cross app domain scenarios.

HTH,
Christoph Schittko
MVP XML
http://weblogs.asp.net/cschittko

[0] http://weblogs.asp.net/cschittko/archive/2004/05/27/143388.aspx

-----Original Message-----
From: erymuzuan [mailto:[email protected]]
Posted At: Sunday, January 02, 2005 7:04 PM
Posted To: microsoft.public.dotnet.framework.aspnet.webservices
Conversation: passing structs (setializable) object in web service
Subject: Re: passing structs (setializable) object in web service

It's true, but you can always manually edit your webreference file, and
replace the object from the WSDL.exe generated with one from your common
project, just make sure you have the XMLNamespace is correct. BTW i'll
always suggest that you use remoting instead. as you have the control of
both the client and the server.


Regards
Erymuzuan Mustapa
Christoph Schittko [MVP] wrote:
Stacy,

The behavior you're describing is a known "weakness" in v1.x of ..NET.
Add Web Reference has no way to recognize types that are in the project
where you are adding the reference to. Furthermore, it doesn't even
re-use proxy classes for XML Schema types referenced from multiple web
services.

In .NET 2.0 you will be able to customize the generation of proxy
classes much better. For now you have to follow the approach outlined
Scott Sealy's article [0].

HTH,
Christoph Schittko
MVP XML
http://weblogs.asp.net/cschittko

[0]
http://msdn.microsoft.com/library/en-us/dnservice/html/service07162002.a
sp?frame=true


-----Original Message-----
From: Stacy Meir [mailto:Stacy (e-mail address removed)]
Posted At: Saturday, January 01, 2005 2:41 AM
Posted To: microsoft.public.dotnet.framework.aspnet.webservices
Conversation: passing structs (setializable) object in web service
Subject: passing structs (setializable) object in web service

i have tried all possible ways and have failed to pass a serializable
struct.
i have three projects: server, client and common. common project

contains

struct mydatapacket marked serializable. i use common project

reference in

other two projects (client and server).

in client project when i create web reference to server project it

imports

a
new type from server project something like
server.mywebreference.mydatapacket, which is different from
common.mydatapacket. how do stop this from happening. or, am i

completly

off
track.

all examples i see pass basic data types and most "complex" pass data
sets.
can someone explain or point me to a resource that discusses in detail
passing of compound data structures in web services (hopefully without
much
soaping and more c# attributing)

thanks
 

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,997
Messages
2,570,240
Members
46,828
Latest member
LauraCastr

Latest Threads

Top