none
Can WCF include custom attributes applied to properties

    Question


  • Is it possible to create a WCF service that can pass custom attributes of an object?

    my code is something like this:

    [DataMember]
    [Description("TestDescription")]
    public int Order{ get; set; }

    I want to be able to reference the attribute class Description on my client side.  I am not sure if this is possible or not.  If it is, how would I accomplish this?
    Thursday, December 18, 2008 9:12 PM

Answers

  • The short answer is that it's not possible. Remember that web service clients may not be using .Net and may not be familiar with the concept of c# attributes. The only information that can be passed is what an xml schema can represent.

    If you will really put some efforts you might be able to achive something like this with custom wsdl exporters and interfering with the client proxy generation but you should avoid it.

    http://webservices20.blogspot.com/
    WCF Security, Performance And Testing Blog
    • Marked as answer by Marco Zhou Tuesday, December 23, 2008 9:55 AM
    Friday, December 19, 2008 12:12 AM

All replies

  • The short answer is that it's not possible. Remember that web service clients may not be using .Net and may not be familiar with the concept of c# attributes. The only information that can be passed is what an xml schema can represent.

    If you will really put some efforts you might be able to achive something like this with custom wsdl exporters and interfering with the client proxy generation but you should avoid it.

    http://webservices20.blogspot.com/
    WCF Security, Performance And Testing Blog
    • Marked as answer by Marco Zhou Tuesday, December 23, 2008 9:55 AM
    Friday, December 19, 2008 12:12 AM
  • There is an MSDN post describing how to add custom description to your WSDL.

    The client won't necessarily do anything with it, but it will be available.

    http://msdn.microsoft.com/en-us/library/ms731731.aspx
    Friday, December 19, 2008 1:41 AM