Solved

Serialize custom attribute of properties

Posted on 2010-09-06
3
1,010 Views
Last Modified: 2012-05-10
 
We have datacontract as below and another class DwPropertyUAttribute (serialized with datacontract) for custom attribute.  Properties are serialized but I need to be serialized custom attribute too. I tried this but no luck. Please commnet experts. Thanks in advance. If you need more details pls ask for the same.

[DataContract(),Serializable()]
    public class wsPrefs
    {
        [DwPropertyUI("TestName","TestLable")]
        [DataMember()]
        public bool SuppressCustomerMode
        {
            get { return true; }
            set { }
        }

        [DataMember()]
        [DwPropertyUI("TestName", "TestLable")]
        public string CustomerDefaultAreaCode
        {
            get { return ""; }
            set { }
        }
     
    }
}


// Custom attribute class

[DataContract(), Serializable()]
    [AttributeUsage(AttributeTargets.Property | AttributeTargets.Class)]
    public class DwPropertyUIAttribute : Attribute
    {

        protected string m_Name;
        protected string m_Label;

        #region "Properties"

        [DataMember()]
        public string Name
        {
            get { return m_Name; }
            set { m_Name = value; }
        }

        [DataMember()]
        public string Label
        {
            get { return m_Label; }
            set { m_Label = value; }
        }

// Reading custom attribute like this

          wsPrefs ws = new wsPrefs();
           
            foreach (PropertyInfo pi in ws.GetType().GetProperties())
      {
                              uiAttributes = (DwPropertyUIAttribute[])pi.GetCustomAttributes(typeof(DwPropertyUIAttribute), false);

}

0
Comment
Question by:RETAILREALM
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 18

Accepted Solution

by:
Richard Lee earned 500 total points
ID: 33609754
Src: http://stackoverflow.com/questions/2829976/send-objects-with-custom-attributes-via-a-wcf-service

WCF is a message based service - you serialize your message on one side, send it across, and receive it on the other side. You're not sending objects as you put it - you only send serialized messages. That's quite an important difference!

Your server and client are totally separate - they don't share anything but the service description (the list of service methods), and the data contracts in the form of a XML schema.

What you get when you create a client is a proxy for the service methods, and a copy of the data contract (looks the same, but different namespace, typically) that has the same signature in the serialized format. That's all there is. You get a new, separate class on the client side, that will serialize into the same format as your original class on the server side.

This means: you'll get the same fields and properties - but that's it. Anything else (like interfaces that are implemented, .NET attributes and more) are not replicated. They cannot be - after all, WCF is interoperable - the client could be a PHP app or a Ruby program. How are they going to handle .NET custom attributes?

So in brief: anything that is .NET specific and goes beyond the simple XML-schema-based data representation cannot be used across a WCF service.

There is a loop hole - if you control both ends of the communication - both server and client - and both are .NET, then you could:

put all your service and data contracts into a separate, shared assembly
reference that assembly in your service implementation on the server side
reference that assembly in your client side proxy
Using this, you'll have one assembly with the same data type on both the server and the client side - and with this "loophole", you can preserve such .NET specifics like attributes between server and client.

DaTribe
0
 

Author Closing Comment

by:RETAILREALM
ID: 33795860
Expecting related solution
0
 
LVL 18

Expert Comment

by:Richard Lee
ID: 33797939
Aladdin might be able to provide that solution
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Article by: Najam
Having new technologies does not mean they will completely replace old components.  Recently I had to create WCF that will be called by VB6 component.  Here I will describe what steps one should follow while doing so, please feel free to post any qu…
This article is for Object-Oriented Programming (OOP) beginners. An Interface contains declarations of events, indexers, methods and/or properties. Any class which implements the Interface should provide the concrete implementation for each Inter…
Michael from AdRem Software explains how to view the most utilized and worst performing nodes in your network, by accessing the Top Charts view in NetCrunch network monitor (https://www.adremsoft.com/). Top Charts is a view in which you can set seve…
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…

627 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question