Serializer not filling data for custom objects

B

brian

Hi, this is probably a one-liner fix, but I can't find that one line!

I have two webservices, UserWS and TroubleWS.

UserWS has a method called GetUserData that accepts a username and
returns a User object filled with data (phone, pager, email, etc).

TroubleWS has methods GetTrouble and SaveTrouble. From the client, I
can call GetTrouble and get a Trouble object filled with data. When I
want to do a save, I pass the Trouble object and a User object. The
User object is that of the currently logged in user. (I can then do
authorization checks in my business logic this way.)

Inside the client, when I get the User object, it's filled with data.
Inside the TroubleWS.SaveTrouble method, the User object is
instantiated, default constructor run, but the properties are NOT
filled. The Trouble object is filled as expected. After I get back
form the SaveTrouble method, checking the User object still shows a
fully filled object.

Oddly enough, if I change the SaveTrouble method to accept a Trouble
object and a generic object instead of a User object, the generic
object has all of the User data. This leads me to believe that maybe
the serializer is ignoring the data when hydrating to the custom
object.

My namespaces on the webservice side are:
brian.data.user:
- UserWS.asmx
- User.cs

brian.data.trouble:
- TroubleWS.asmx
- Trouble.cs

I can try this in the reverse and I get similar results. That is, I
created a public void Test(Trouble trouble) method on UserWS. When I
call that method and check the Trouble object, it is blank just like
the other case.

I'm really stuck. None of the properties on my objects are marked
read only. All of them have setters implemented. No exceptions are
being thrown and I'm pulling my hair out! -:)

Thanks in advance,
-Brian
 
B

brian

Hi,

A friend of a friend helped me find the fix. Indeed, it was a
one-liner. For all of the objects that were being serialized, I
needed to decorate them with the XmlType attribute.

For example:
[XmlType( TypeName="User",
Namespace="http://website.com/brian/data/user/" )]
public class User : IComparable { .... }

Apparently, this tells the serializer to bind my objects to the
appropriate xml namespace.

Thanks to those who read my original message.
-Brian
 

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,994
Messages
2,570,223
Members
46,813
Latest member
lawrwtwinkle111

Latest Threads

Top