check property exists or not when consuming WCF RRS feed

  • Question

  • Hi,


    I am using web service which again consumes WCF service. Now I have to maintain compatibility so that my updated web service can run with same older WCF service. Suppose:

    WCF v1 have two property: prop1 and prop2 for one class and my web service is getting that value.

    Next in WCG v2, 3rd property added prop3. So, I updated my web service with this property.

    But here I want to add condition like:

    var type = objectToCheck.GetType();
        return type.GetProperty("prop3") != null;

    Then, web service get the value from that property. In this way, I am trying to maintain compatibility without worrying about WCF changes.

    But in my case, this never returns correct. I also tried some other codes but no luck.

    Could you please suggest me how can I fix this?

    Also, if someone provide some good way to handle version, it will be great for me.

    Thank you,


    Kaushal Kumar


    • Moved by Jason Dot Wang Monday, October 15, 2012 8:15 AM This thread is about WCF (From:Visual C# Language)
    Thursday, October 11, 2012 4:18 PM

All replies

  • Probably GetType returns a type from your new version. If there is no better solution based on WCF features, then try adding a function ‘CheckProperty’ to your WCF v1. I think that in any version of your service it will check if a property exists on server.

    • Edited by Viorel_MVP Thursday, October 11, 2012 6:30 PM
    Thursday, October 11, 2012 6:28 PM
  • Hi Kaushal

    Web services try to be pretty type safe and you have to "update references" when the interface changes.

    We usually have a SINGLE method, e.g. "void AddEmployee(string)" or "string DoSomethingWith(string)" but instead of specifying an X amount of parameters, we send or receive an XML string.

    You can add and remove anything from the XML string input parameter (or return value) because it is valid for XML to throw away attributes with NULL values, and adding new attributes and elements won't break anything.

    Consider the following XML string for "AddEmployee(string info)":

    <Employee name="Rose" surname="Rosevelt" />

    You can easily add a language or other property without breaking any interfaces of the web service?

    <Employee name="Rose" surname="Rosevelt" language="20" />

    Does this make sense? Or are you looking for another solution?

    Thursday, October 11, 2012 7:17 PM
  • Hi All,


    For Viorel: Yes, if we get this function in WCF, it will handle.

    WCF is not under our control :(. So, somehow I need to find solution in web service end only.

     Martin, you provided good way. But we cannot go with this solution. I think, it should be planned in starting. I have already web service and I have no control over WCF.

    So, I am just looking for the property check. One way is in my mind that:

    1. create one fucn in Web service. Pass object and prop name.

    2.Try to get value from that proper under try/catch block. if error occur, that function will return false.

    But not sure about the drawback of such type of things.

    Please provide me some solution for me.Regards,

    Kaushal Kumar


    Friday, October 12, 2012 3:19 AM
  • Hi kaushal.k,


      Welcome to MSDN Forum Support.

      You are more likely to get more efficient responses to WCF Development issues at where you can contact WCF experts,so I would like to redirect you to appropriate forum for better responses.


      Jason Wang

    Jason Wang [MSFT]
    MSDN Community Support | Feedback to us

    Monday, October 15, 2012 8:13 AM
  • Hi Kaushal,

    There are different ways in which you solve this versioning issues.

    • Like sending an additional header about the service version information from wcf service.
    • By using IsRequired attribute on the data member can also solve the issue.

    For details about how to deal with versions of services please refer to msdn for service versioning and challanges.

    Monday, October 29, 2012 5:58 PM