How to serialize a protected property in wcf

Posted by Denis Rosca on Stack Overflow See other posts from Stack Overflow or by Denis Rosca
Published on 2010-05-30T18:46:51Z Indexed on 2010/05/30 18:52 UTC
Read the original article Hit count: 427

Filed under:
|
|

Hello, i need some help with wcf serializing.

I have two classes Person and Address. The Address class looks like this:

public class Adresa : IExtensibleDataObject
{
    private Guid _id;
    [DataMember]
    protected virtual Guid Id
    {
        get { return _id; }
        set { _id = value; }
    }

    private ExtensionDataObject _extensionData;
    [DataMember]
    public virtual ExtensionDataObject ExtensionData
    {
        get
        {
            return _extensionData;
        }
        set
        {
            _extensionData = value;
        }
    }

    private string _street;
    [DataMember]
    public virtual string Street
    {
        get { return this._cUTAM; }
        set { this._cUTAM = value; }
    }

private string _number;
    [DataMember]
public virtual string Number 
{
     get { return this._number; }
     set { this._number = value; }
}

private string _postalCode;
[DataMember]
public virtual string PostalCode 
{
    get { return this._postalCode; }
    set { this._postalCode = value; }
}

    // and some other stuff related to the address        
}

The Person class looks like this:

public class PersoanaFizica :IExtensibleDataObject
{
    private Guid _id;
    [DataMember]
    protected virtual Guid Id
    {
        get { return _id; }
        set { _id = value; }
    }

    private ExtensionDataObject _extensionData;
    [DataMember]
    public virtual ExtensionDataObject ExtensionData
    {
        get
        {
            return _extensionData;
        }
        set
        {
            _extensionData = value;
        }
    }

    private string _firstName;
    [DataMember]
public virtual string FirstName 
{
    get { return this._firstName; }
    set { this._firstName = value; }
}

private string _lastName;
[DataMember]
public virtual string LastName 
{
    get { return this._lastName; }
    set { this._lastName = value; }
}

}

The problem is that when the wcf client the data the Id properties are set to a bunch of zeros ( something like 000000-0000-000000-0000000).

Any ideas on why this is happening? Thanks, Denis.

© Stack Overflow or respective owner

How to serialize a protected property in wcf

Posted by Denis Rosca on Stack Overflow See other posts from Stack Overflow or by Denis Rosca
Published on 2010-05-30T19:38:17Z Indexed on 2010/05/30 19:42 UTC
Read the original article Hit count: 427

Filed under:
|
|

Hello everyone, I have to classes (Person and Address) that i need to send via wcf, the classes look like this:

public class PersoanaFizica :IExtensibleDataObject
{
    [DataMember]
    private Guid _id;
    [DataMember(Name = "Id")]
    protected virtual Guid Id
    {
        get { return _id; }
        set { _id = value; }
    }

    private ExtensionDataObject _extensionData;
    public virtual ExtensionDataObject ExtensionData
    {
        get
        {
            return _extensionData;
        }
        set
        {
            _extensionData = value;
        }
    }


    private string _firstName;
    [Searchable(PropertyName="FirstName")]
    [DataMember]
    public virtual string FirstName 
    {
        get { return this._firstName; }
        set { this._firstName = value; }
    }

    private string _lastName;
    [Searchable(PropertyName="LastName")]
    [DataMember]
    public virtual string LastName 
    {
        get { return this._lastName; }
        set { this. _lastName = value; }
    }

    private Address _address;
    [Searchable(PropertyName="Address")]
    [DataMember]
    public virtual Address Address 
    {
        get { return this._address; }
        set { this._address = value; }
    }
}

public class Address : IExtensibleDataObject
{
 [DataMember]
    private Guid _id;
    [DataMember]
    public virtual Guid Id
    {
        get { return _id; }
        set { _id = value; }
    }

    private ExtensionDataObject _extensionData;
    public virtual ExtensionDataObject ExtensionData
    {
        get
        {
            return _extensionData;
        }
        set
        {
            _extensionData = value;
        }
    }

        private string _country;
    [Searchable(PropertyName="Country")]
    [DataMember]
    public virtual string Country 
    {
        get { return this._country; }
        set { this._country = value; }
    }
// and some other properties related to the address
}

The problem is that when i try to send them via wcf, the client recieves the Id properties set to 00000-0000-00000-00000 or smth like this. Any idea why this is happening? And how to serialize the proper values?

Thanks,Denis.

© Stack Overflow or respective owner

Related posts about c#

Related posts about wcf