WCF method that updates object passed in

Posted by Georgia Brown on Stack Overflow See other posts from Stack Overflow or by Georgia Brown
Published on 2010-03-31T14:41:28Z Indexed on 2010/03/31 14:43 UTC
Read the original article Hit count: 339

Filed under:

Am I correct in thinking that if I have a WCF OperationContract takes in an object and needs to set a property on that object so the client gets the update, I need to declare it to return the object.

e.g. given a datacontract:

[DataContract]
public class CompositeType
{
    [DataMember]
    public int Key { get; set; }

    [DataMember]
    public string Something { get; set; }
}

this will not work with WCF:

public void GetDataUsingDataContract(CompositeType composite)
{
  composite.Key = 42;              
}

this will work:

public CompositeType GetDataUsingDataContract(CompositeType composite)
{
  composite.Key = 42;

  return new CompositeType
  {
    Key = composite.Key,
    Something = composite.Something
  };           
}

© Stack Overflow or respective owner

Related posts about wcf