Serializing custom business objects

M

Michael_vb

It seems if i have a custom business object that inherits from an
arraylist, it will not serialize it correctly on the proxy side.Well my
issue is that i have a business object that has a member of
phonenumbers which inherits from arraylist. The reason is because i
could have more than one phone number. How can i get around this issue
on the proxy side, here is my code

Web service code
<WebMethod()> Public Function SaveCase(ByVal Myrequest As CaseRequest)


End Function
End Class

<System.Serializable()> Public Class CaseRequest
Public FirstName As String
Public LastName As String
Private _phone As PhoneNumbers

Public Property Phone() As PhoneNumbers
Get
Return _phone
End Get
Set(ByVal value As PhoneNumbers)
_phone = value
End Set
End Property

End Class

<System.Serializable()> Public Class PhoneNumbers
inherits arraylist
Public Type As String
Public Number As String
Public Sub New()
End Sub
End Class


On the client side there is no Phonenumbers class created,also the
member phone from the caserequest class is not an arraylist. Any
ideas!!

asp.net web service 2.0
 
J

John Saunders

Michael_vb said:
It seems if i have a custom business object that inherits from an
arraylist, it will not serialize it correctly on the proxy side.Well my
issue is that i have a business object that has a member of
phonenumbers which inherits from arraylist. The reason is because i
could have more than one phone number. How can i get around this issue
on the proxy side, here is my code

ArrayList is a platform-specific type. You should not use platform-specific
types in a web service. What do you expect a Java client to do with your
ArrayList, for example?

John
 
M

Michael_vb

No this is a .net to .net application
John said:
ArrayList is a platform-specific type. You should not use platform-specific
types in a web service. What do you expect a Java client to do with your
ArrayList, for example?

John
 
J

John Saunders

Michael_vb said:
No this is a .net to .net application

But you're using Web Services, which is a platform-independent paradigm. You
are therefore subject to its limitations. Among other things the
..NET-specific details of your type are not communicated between client and
server.

I would suggest returning an array instead of an arraylist. If the client
then decides to further manipulate the data using an ArrayList, it is free
to do so.

If you require type-fidelity, you should consider using .NET Remoting,
despite the predictions of its demise.

John
 
K

kferron

Michael, this is a little off topic of your direct question, but you
should first of all consider not using a derived class of ArrayList for
*any* of your collections. Consider instead that if you have a
PhoneNumber type that is serializable, using a generic collection that
you can attribute serialization rules to would be ideal in your
situation. The client will still have to know how to hydrate the
appropiate types on their end.

~kcf
 

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,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top