.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
Sign In
Win Surprise Gifts!!!

Top 5 Contributors of the Month
Gaurav Pal
Post New Web Links

How do I serialize a DataMember in a DataContract as an XML attribute

Posted By:      Posted Date: September 29, 2010    Points: 0   Category :WCF

Hello guys,

I have the following class what I return on my WCF webservice;


[DataContract(Namespace = "http://schemas.pi.operational.petrobras.com.br")]
  public class SimpleMeasure
    private DateTime? measureDate;
    private string value;

    public DateTime? MeasureDate
      get { return measureDate; }
      set { measureDate = value; }

    public string Value
      get { return this.value; }
      set { this.value = value; }


Ho do I make it return a soapResponse like this ?

<SimpleMeasure <

View Complete Post

More Related Resource Links

Problem: DataContract and DataMember attributes are not being recognized

I am having a strange problem. My service is otherwise working fine. However, now I want to add a custom object to be sent over to clients. I created a class to hold the data applied DataContract and DataMember attributes. However, compiler is not recognizing these attributes and giving me following error. The type or namespace name 'DataContractAttribute' could not be found (are you missing a using directive or an assembly reference?)  I could not figure our what assembly do I need to refer to. I am using VS2010 on WinXP. Thanks. kr

Can serialize but not deserialize class containing an xs:list attribute using XmlSerializer

I have a simple serializable class along the lines of: [Serializable] [XmlType] public class MyClass { [XmlAttribute("values")] public int[] Values { get; set; } } If I create an instance of this class with Values set to an empty collection the XmlSerializer class produces this output as expected: <?xml version="1.0" encoding="utf-16" ?> <MyClass xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" values="" /> However, deserializing this exact output throws a System.FormatException: Input string was not in a correct format. Shouldn't the XmlSerializer be able to deserialize this, since it produced the xml string in the first place?

From DataContract to MessageContract: ClientBase can't serialize / deserialze



few days ago i switch from DataContracts to MessageContracts. I'm posting a little sample:

This is my unmodified operation:

ReadDataSourcesResponse ReadDataSources(ReadDataSourcesRequest request);

This are the request- and response contracts before:

public sealed class ReadDataSourcesRequest { }

public  sealed class
public ReadDataSourcesResponse(DataSourceContractCollection dataSources)
  _dataSources = dataSources;

private DataSourceContractCollection _dataSources;

public DataSourceContractCollection DataSources
 if (_dataSources == null)
  _dataSources = new DataSourceContractCollection();
  return _dataSources;

I modified these to:

 public sealed class ReadDataSourcesRequest


how to serialize objects ??


Is there any way or process to serialize the the objects?? i am trying to store the instance of few control in viewstate but it shows error msg that it is not a serialized object. should i perform some steps to serialize the objects ???

I am not able to read xml file with XDocument if its Descendants has Attribute xmlns="http://abc.co


I am not able to read xml file with XDocument if its Descendants has  Attribute like:-

<?xml version="1.0" encoding="utf-8" standalone="yes"?>
  <row ID="1" xmlns="http://www.opentravela.org/OTA/2003/05">
    <var country_name="Caribbean and Rest of the world" city_name="Kingston" flight_category="Economy Class" via="Atlanta" flight_departure="London Heathrow" airline_logo="Delta" adult_fare="Delta" child_fare="660" infant_fare="561" date1="132" date2="2010-08-15" />


I don't know what to do ?

Looking for some help..

Category attribute of user control property does not work correctly in categories tab.



I have a User Control (ascx) and a property which a want to display in my categories tab in Visual Studio in the category named "Styles".

[Category("Styles"), DefaultValue(""), Description("The value for formating something.")]
public String MyFormatProperty
set { /* the code for set */; }
get { /* the code for get */; }

And here is the problem: Actually I do not need a get, because I only have to set the property (write only property). But when I omit the get, the property is displayed in the "Misc" category in the categories tab in Visual Studio. Only when I code the get as well, then the property is displayed correctly in the "Styles" category in the categories tab in Visual Studio.

Does anybody know why? How can I display the category correctly only with set?

Thanks, S.

Make sure that the class defined in this code file matches the 'inherits' attribute, and that it e


Here is the page directive for the page that throws the error:

@ Page language="c#" Inherits="University.AspNet.Index" CodeFile="Index.aspx.cs" %>

The code behind file Index.aspx.cs starts like this:

using University.Framework.UI;

namespace University.AspNet

public partial class Index : University.Framework.UI.HomePage

The code behind is extending this HomePage class, which is in turn an extenstion of another class University.Framework.UI.Page, which extends the System.Web.UI.Page class.

Am I misusing the I

Security Briefs: Hashing Passwords, The AllowPartiallyTrustedCallers Attribute


Keith Brown describes how yo can hash passwords when you want to store them in your own custom database, and when to use the AllowPartiallyTrustedCallers attribure on your assembly.

Keith Brown

MSDN Magazine August 2003

"Content for this URL is excluded by the server because a no-index attribute." in crawl logs


Hi All,

I am getting following error message in Crawl Logs

" Content for this URL is excluded by the server because a no-index attribute. "

Any help in this regard will be greatly appreciated.



ReadOnly DateTime attribute stores correct date but only retrieves DateTime.MinValue on Delete


Hey everyone,

I have a dynamic data site that stores Event data using LINQ-to-SQL. When someone requests an event, it is first stored as a PendingEvent (which is a child of Event) with a column/attribute called receivedAt, which is [ReadOnly(true)] and which is assigned in InsertEvent as shown.

        partial void InsertEvent(Event instance)
            instance.requestedAt = DateTime.Now;




This works fine. The event displays with the correct receivedAt date, and it's correct in my database. It shows up just fine on my Display, Edit, and List pages. However, if I try to delete, the receivedAt in the instance (retrieved with my debugger) in my delete function is 01/01/0001 12:00am, also known as DateTime.MinValue. My other dates appear correct.

If I remove "ReadOnly(true)" from the received at, everything works fine. Why won't "ReadOnly" allow me to have a time?
Thanks in advance,



I forgot to mention why I care. I can't submit the instance to be deleted because DateTime.MinValue is outside SQL's available datetime, so I get a SQL error. The delete also takes place in a custom dele

chnage data of input type with readonly attribute


I have webform where i have different input type as text controls with a readonly attribute. I have option to edit the data so through javascript i remove the readonly attribute through javascript, here's the code 
function EditBillAddress()

what are the possible values for the UIHint attribute in DynamicData


All --

Please help.

I need to know-- what are the possible values for the UIHint attribute in DynamicData?

I am using DotNet 3.5 and VisualStudio 2008.

I know that I can use the name of each *.cs file in the "DynamicData\FieldTemplates\" folder BUT what other names are available?

For instance, in DynamicData Futures, I have seen UIHint[("IntegerSlider")] which I think comes from Ajax BUT there is no such FieldTemplate so where is it getting that resolution?

Please advise.

Thank you.

-- Mark Kamoski

Custom Validation Attribute is not called by validation mechanism.

Hello everyone I have create custom validation attribute and assign it to class level validation. Unfortunately, it is not called. I try every way that it think it could be solve the problem. However, it take me for hours and I can't find the attribute is not called by validation mechanism.For illustrate you I put the following code.Attribute[AttributeUsage(AttributeTargets.Class, AllowMultiple = true, Inherited = true)] public sealed class BooleanDependencyAttribute : ValidationAttribute { private const string _defaultErrorMessage = "?????????{0}"; private readonly object _typeId = new object(); public string DependencyPropertyName { get; private set; } public string DependentPropertyName { get; private set; } public BooleanDependencyAttribute(string dependencyPropertyName, string dependentPropertyName) : base(_defaultErrorMessage) { DependencyPropertyName = dependencyPropertyName; DependentPropertyName = dependentPropertyName; } public override object TypeId { get { return _typeId; } } public override string FormatErrorMessage(string name) { return String.Format(CultureInfo.CurrentUICulture, ErrorMessageString,name); } public override bool

Store Attribute to string

Hello,I have been trying to store an xml attribute value to a string and I cannot seem to get it to work.  I start off pulling an XML node from a SharePoint web service. XmlNode user = usergrpService.GetUserInfo("domain\\user"); This seems to work because if I assign user.InnerXml to a text box then I can see the contents of the user.  So then I try to get the value.I have tried a combination of the following with /'s, @'s, User/ID, User@ID, /User/ID, /User@ID, etc.  String userID = user.Attributes["ID"].Value; String userID = user.SelectSingleNode("ID").Value; Each time I get an "Object reference not set to an instance of an object" error.  If I can read the InnerXml then why can I not get a single attribute?-Eric

How to: Serialize Hashtable contained inside another object that is serialized as an array of object

Update:  I've added the entire program in a single block of C# text near the end of these posts that can be placed into a C# Program.cs file of a console project.   I have a class called MyHashtable that inherits from Hashtable and implements IXmlSerializable.  MyHashtable is contained inside another object called MyObject and I need to xml serialize an array of MyObject[].  Whenever I xml deserialize, the hashtable is deserialized, but only 1 of MyObjects from the MyObject[] array is deserialized.  The ReadXml uses "while (reader.NodeType != XmlNodeType.EndElement)" so I don't think the reader is consuming all of the xml internally.   Does anyone know why this is happening?  Thanks.    

WSE 3.0 Can't Serialize String Types as Escaped CDATA

I know I should be using WCF.  HOWEVER, I'm utilizing services provided by Omniture that simply only work well with WSE 3.0 as Omniture's WSDL definitions and service endpoints have compatibility issues that are beyond my control.   While I was able to solve a lot of my compatibility problems with Omniture but there is one issue that is still causing me a lot of heartburn.  When passing strings values through WSE3.0 the Microsoft.Web.Services3.WebServicesClientProtocol class encodes the values as denoted below for the "script" argument.         <soap:Body soap:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">       <tns:ProductSubmitProductScript>       <productCode xsi:type="xsd:string">123456789</productCode>       <script xsi:type="xsd:string">&lt;genesis&gt;&lt;/genesis&gt;</script>       </tns:ProductSubmitProductScript>    Unfortunately, this encoding isn't going is promptly rejected by Omniture because the xml values are not subsequently decoded on their side.  When passing string values to Omniture they MUST be enclosed in the escape sequenice <![CDATA[ ]]>.  Thus, the prior request should be
ASP.NetWindows Application  .NET Framework  C#  VB.Net  ADO.Net  
Sql Server  SharePoint  Silverlight  Others  All   

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend