views:

305

answers:

1

Hi,

I have my custom class Customer with its properties. I added DataContract mark above the class and DataMember to properties and it was working fine, but I'm calling a service class's function, passing customer instance as parameter and some of my properties get 0 values.

While debugging I can see my properties values and after it gets to the function, some properties' values are 0. Why it can be so?

There's no code between this two actions. DataContract mark workes fine, everything's ok. Any suggestions on this issue?

I tried to change ByRef to ByVal, but it doesn't change anything. Why it would pass other values right and some of integer types just 0?

Maybe the answer is simple, but I can't figure it out.

Thank You.

  <DataContract()> 
    Public Class Customer 
    Private Type_of_clientField As Integer = -1 

      <DataMember(Order:=1)>  
      Public Property type_of_client() As Integer 
        Get 
          Return Type_of_clientField 
        End Get 
        Set(ByVal value As Integer) 
          Type_of_clientField = value 
        End Set 
      End Property 
    End Class 

    <ServiceContract(SessionMode:=SessionMode.Allowed)> 
    <DataContractFormat()> 
    Public Interface CustomerService 

    <OperationContract()> 
    Function addCustomer(ByRef customer As Customer) As Long 

    End Interface

type_of_client properties value is 6 before I call addCustomer function. After it enters that function the value is 0.

UPDATE: The issue is in instance creating.

When I create an instance of a class on client side, that is stored on service side, some of my properties pass 0 or nothing, but when I call a function of a service class, that returns a new instance of that class, it works fine.

What's is the difference? Could that be serialization issue?

+1  A: 

If you're using the order parameter of datamember must start at 0 and increment (i.e. make 1 into 0, the next datamember becomes 1, etc). This might work if you had more than one member, however it has nowhere to put your variable as there is no 1 position for the class you show.

Steve
If I add order to some of my class's properties, won't wcf generate order parameter to other properties automatically? I can see order parameter on all class's parameters in reference.vb. I'm not sure, if I got your answer right.
hgulyan
It's just a small part of my class and service functions. My properties do start from 1. Thank you for that information.Could that really cause this kind of problem or maybe not just in that? Why it would pass most of parameters right and others not?
hgulyan
The order in my reference.vb doesn't match to order of datamembers' order parameter.
hgulyan