Solved

Serialize custom attribute of properties

Posted on 2010-09-06
3
1,008 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

Salesforce Has Never Been Easier

Improve and reinforce salesforce training & adoption using WalkMe's digital adoption platform. Start saving on costly employee training by creating fast intuitive Walk-Thrus for Salesforce. Claim your Free Account Now

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
C# DataTable (in memory) vs SQL Lookups 4 75
What!!!??? 5 61
How does this modal work? 3 34
XML Constructor Throwing Incorrectly Structured Document Error 4 24
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…
Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an antispam), the admini…
Suggested Courses

751 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