I'm afraid there's no simple and easy answer to this issue. As you've
noticed, the XML serializer serializes only public fields and read-write
properties. The data format is customizable to some extent, but all private
state and behavior associated with your classes is lost.
That said, it is possible to hack around this issue. You can edit the
consumer-side proxy, remove the data classes generated along with the proxy
and have the proxy refer to the original class(es). This does allow you to
share the same type between the web service and the consumer and thus share
behavior, but private state is still lost.
The bottom line is that if you really want to share objects between a
service and its consumers, then you might want to consider using a
distributed object technology such as .NET Remoting. Web Services merely
pass XML documents back and forth, and trying to share types or behavior
will run into issues.
Regards,
Sami
>I have a class called 'PrimaryKey' that represents the primary key of a
>table.
[quoted text clipped - 29 lines]
> Thanks in advance
> Dave A
Dave A - 31 May 2005 10:23 GMT
Thanks. I appreciate the effort that you put into that great answer.
There has to be a solution though. I am going to keep thinking about it and
if I come up with something then I will post back what I find.
> I'm afraid there's no simple and easy answer to this issue. As you've
> noticed, the XML serializer serializes only public fields and read-write
[quoted text clipped - 51 lines]
>> Thanks in advance
>> Dave A
Dave A - 31 May 2005 14:49 GMT
I knew there had to be an answer and there is!
It just barely works with .NET 1.x -
http://dotnetified.com/PermaLink.aspx?guid=E86B447E-AA95-49B6-909F-CDA36ACF481F
And it fully works with .NET
2.0 -http://weblogs.asp.net/cweyer/archive/2004/08/02/205798.aspx
Dave A
('Exposing private members using SOAP and XML Serialization' - that is there
for google)
> Thanks. I appreciate the effort that you put into that great answer.
>
[quoted text clipped - 58 lines]
>>> Thanks in advance
>>> Dave A
Sami Vaaraniemi - 01 Jun 2005 07:53 GMT
Indeed, you can serialize a private field as shown in the article by
overriding the serialization for the object. You could also do this with a
wrapper class and a bit of reflection.
However, (I think) in the consumer the field now becomes public in the
generated class so the behavior (encapsulation) is lost. The consumer will
be able to access the PrimaryKey value directly which is what I believe you
wanted to avoid.
Regards,
Sami
>I knew there had to be an answer and there is!
>
[quoted text clipped - 75 lines]
>>>> Thanks in advance
>>>> Dave A