Search code examples
c#web-serviceswcf

Update WCF Web Service Reference


I have a WCF SOAP service and recently changed the response of that method. I have other applications consuming this method. I did not change the method name, parameters it accepts. The only change I made is that I added 2 new properties to the response object. Explanation is as below,

Method:

Public Class2 GetData(SampleClass1 data, bool extraStuffRequired)
{
    var obj = new Class2();
    //Process data here and load into obj
    return obj;
}

Definition of Class2 Before Change:

Public class Class2
{
public string p1 {get; set;}
public string p2 {get; set;}
}

Definition of Class2 After Change:

Public class Class2
{
public string p1 {get; set;}
public string p2 {get; set;}

public string p3 {get; set;}
public string p4 {get; set;}
}

Note that I have added 2 new properties p3 and p4 and based on busniess logic, i would either populate values in them or set them to empty string.

ConsumingApp1 wants these new properties so they update the service reference and get the classes generated and use the new properties(p3 and p4).

ConsumingApp2 does not want them but they do call the method but only use p1 & p2.

My Question is, do I need to force ConsumingApp2 to update their service reference or would it actually work just fine without ConsumingApp2 making any changes ?


Solution

  • No, ConsumingApp2 should be fine without updating the Service Reference. So, Missing values for p3, p4 would be initialized to default value. In your case, since p3, p4 are of type String, they would be initialized to null.

    For DataContract Version rule are following

    1. If you Add new non-required members, then Client would remain unaffected and Missing values are initialized to defaults.

    2. If you Add new required members, then Client would be affected and Exception is thrown.

    A screenshot summarizing From [MSDN].1Also you can read more about Service Versioning & Versioning Strategy enter image description here

    Note: In your posted question, you haven't declared any DataContract or DataMember for the datatypes.