Search Results

Search found 9 results on 1 pages for 'iextensibledataobject'.

Page 1/1 | 1 

  • XmlSerializer equivalent of IExtensibleDataObject

    - by demoncodemonkey
    With DataContracts you can derive from IExtensibleDataObject to allow round-tripping to work without losing any unknown additional data from your XML file. I can't use DataContract because I need to control the formatting of the output XML. But I also need to be able to read a future version of the XML file in the old version of the app, without losing any of the data from the XML file. e.g. XML v1: <Person> <Name>Fred</Name> </Person> XML v2: <Person> <Name>Fred</Name> <Age>42</Age> </Person> If reading an XML v2 file from v1 of my app, deserializing and serializing it again turns it into an XML v1 file. i.e. the "Age" field is erased. Is there anything similar to IExtensibleDataObject that I can use with XmlSerializer to avoid the Age field disappearing?

    Read the article

  • How to serialize a protected property in wcf

    - by Denis Rosca
    Hello, i need some help with wcf serializing. I have two classes Person and Address. The Address class looks like this: public class Adresa : IExtensibleDataObject { private Guid _id; [DataMember] protected virtual Guid Id { get { return _id; } set { _id = value; } } private ExtensionDataObject _extensionData; [DataMember] public virtual ExtensionDataObject ExtensionData { get { return _extensionData; } set { _extensionData = value; } } private string _street; [DataMember] public virtual string Street { get { return this._cUTAM; } set { this._cUTAM = value; } } private string _number; [DataMember] public virtual string Number { get { return this._number; } set { this._number = value; } } private string _postalCode; [DataMember] public virtual string PostalCode { get { return this._postalCode; } set { this._postalCode = value; } } // and some other stuff related to the address } The Person class looks like this: public class PersoanaFizica :IExtensibleDataObject { private Guid _id; [DataMember] protected virtual Guid Id { get { return _id; } set { _id = value; } } private ExtensionDataObject _extensionData; [DataMember] public virtual ExtensionDataObject ExtensionData { get { return _extensionData; } set { _extensionData = value; } } private string _firstName; [DataMember] public virtual string FirstName { get { return this._firstName; } set { this._firstName = value; } } private string _lastName; [DataMember] public virtual string LastName { get { return this._lastName; } set { this._lastName = value; } } } The problem is that when the wcf client the data the Id properties are set to a bunch of zeros ( something like 000000-0000-000000-0000000). Any ideas on why this is happening? Thanks, Denis.

    Read the article

  • How to serialize a protected property in wcf

    - by Denis Rosca
    Hello everyone, I have to classes (Person and Address) that i need to send via wcf, the classes look like this: public class PersoanaFizica :IExtensibleDataObject { [DataMember] private Guid _id; [DataMember(Name = "Id")] protected virtual Guid Id { get { return _id; } set { _id = value; } } private ExtensionDataObject _extensionData; public virtual ExtensionDataObject ExtensionData { get { return _extensionData; } set { _extensionData = value; } } private string _firstName; [Searchable(PropertyName="FirstName")] [DataMember] public virtual string FirstName { get { return this._firstName; } set { this._firstName = value; } } private string _lastName; [Searchable(PropertyName="LastName")] [DataMember] public virtual string LastName { get { return this._lastName; } set { this. _lastName = value; } } private Address _address; [Searchable(PropertyName="Address")] [DataMember] public virtual Address Address { get { return this._address; } set { this._address = value; } } } public class Address : IExtensibleDataObject { [DataMember] private Guid _id; [DataMember] public virtual Guid Id { get { return _id; } set { _id = value; } } private ExtensionDataObject _extensionData; public virtual ExtensionDataObject ExtensionData { get { return _extensionData; } set { _extensionData = value; } } private string _country; [Searchable(PropertyName="Country")] [DataMember] public virtual string Country { get { return this._country; } set { this._country = value; } } // and some other properties related to the address } The problem is that when i try to send them via wcf, the client recieves the Id properties set to 00000-0000-00000-00000 or smth like this. Any idea why this is happening? And how to serialize the proper values? Thanks,Denis.

    Read the article

  • WCF – interchangeable data-contract types

    - by nmarun
    In a WSDL based environment, unlike a CLR-world, we pass around the ‘state’ of an object and not the reference of an object. Well firstly, what does ‘state’ mean and does this also mean that we can send a struct where a class is expected (or vice-versa) as long as their ‘state’ is one and the same? Let’s see. So I have an operation contract defined as below: 1: [ServiceContract] 2: public interface ILearnWcfServiceExtend : ILearnWcfService 3: { 4: [OperationContract] 5: Employee SaveEmployee(Employee employee); 6: } 7:  8: [ServiceBehavior] 9: public class LearnWcfService : ILearnWcfServiceExtend 10: { 11: public Employee SaveEmployee(Employee employee) 12: { 13: employee.EmployeeId = 123; 14: return employee; 15: } 16: } Quite simplistic operation there (which translates to ‘absolutely no business value’). Now, the data contract Employee mentioned above is a struct. 1: public struct Employee 2: { 3: public int EmployeeId { get; set; } 4:  5: public string FName { get; set; } 6: } After compilation and consumption of this service, my proxy (in the Reference.cs file) looks like below (I’ve ignored the rest of the details just to avoid unwanted confusion): 1: public partial struct Employee : System.Runtime.Serialization.IExtensibleDataObject, System.ComponentModel.INotifyPropertyChanged I call the service with the code below: 1: private static void CallWcfService() 2: { 3: Employee employee = new Employee { FName = "A" }; 4: Console.WriteLine("IsValueType: {0}", employee.GetType().IsValueType); 5: Console.WriteLine("IsClass: {0}", employee.GetType().IsClass); 6: Console.WriteLine("Before calling the service: {0} - {1}", employee.EmployeeId, employee.FName); 7: employee = LearnWcfServiceClient.SaveEmployee(employee); 8: Console.WriteLine("Return from the service: {0} - {1}", employee.EmployeeId, employee.FName); 9: } The output is: I now change my Employee type from a struct to a class in the proxy class and run the application: 1: public partial class Employee : System.Runtime.Serialization.IExtensibleDataObject, System.ComponentModel.INotifyPropertyChanged { The output this time is: The state of an object implies towards its composition, the properties and the values of these properties and not based on whether it is a reference type (class) or a value type (struct). And as shown above, we’re actually passing an object by its state and not by reference. Continuing on the same topic of ‘type-interchangeability’, WCF treats two data contracts as equivalent if they have the same ‘wire-representation’. We can do so using the DataContract and DataMember attributes’ Name property. 1: [DataContract] 2: public struct Person 3: { 4: [DataMember] 5: public int Id { get; set; } 6:  7: [DataMember] 8: public string FirstName { get; set; } 9: } 10:  11: [DataContract(Name="Person")] 12: public class Employee 13: { 14: [DataMember(Name = "Id")] 15: public int EmployeeId { get; set; } 16:  17: [DataMember(Name="FirstName")] 18: public string FName { get; set; } 19: } I’ve created two data contracts with the exact same wire-representation. Just remember that the names and the types of data members need to match to be considered equivalent. The question then arises as to what gets generated in the proxy class. Despite us declaring two data contracts (Person and Employee), only one gets emitted – Person. This is because we’re saying that the Employee type has the same wire-representation as the Person type. Also that the signature of the SaveEmployee operation gets changed on the proxy side: 1: [System.CodeDom.Compiler.GeneratedCodeAttribute("System.ServiceModel", "4.0.0.0")] 2: [System.ServiceModel.ServiceContractAttribute(ConfigurationName="ServiceProxy.ILearnWcfServiceExtend")] 3: public interface ILearnWcfServiceExtend 4: { 5: [System.ServiceModel.OperationContractAttribute(Action="http://tempuri.org/ILearnWcfServiceExtend/SaveEmployee", ReplyAction="http://tempuri.org/ILearnWcfServiceExtend/SaveEmployeeResponse")] 6: ClientApplication.ServiceProxy.Person SaveEmployee(ClientApplication.ServiceProxy.Person employee); 7: } But, on the service side, the SaveEmployee still accepts and returns an Employee data contract. 1: [ServiceBehavior] 2: public class LearnWcfService : ILearnWcfServiceExtend 3: { 4: public Employee SaveEmployee(Employee employee) 5: { 6: employee.EmployeeId = 123; 7: return employee; 8: } 9: } Despite all these changes, our output remains the same as the last one: This is type-interchangeability at work! Here’s one more thing to ponder about. Our Person type is a struct and Employee type is a class. Then how is it that the Person type got emitted as a ‘class’ in the proxy? It’s worth mentioning that WSDL describes a type called Employee and does not say whether it is a class or a struct (see the SOAP message below): 1: <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" 2: xmlns:tem="http://tempuri.org/" 3: xmlns:ser="http://schemas.datacontract.org/2004/07/ServiceApplication"> 4: <soapenv:Header/> 5: <soapenv:Body> 6: <tem:SaveEmployee> 7: <!--Optional:--> 8: <tem:employee> 9: <!--Optional:--> 10: <ser:EmployeeId>?</ser:EmployeeId> 11: <!--Optional:--> 12: <ser:FName>?</ser:FName> 13: </tem:employee> 14: </tem:SaveEmployee> 15: </soapenv:Body> 16: </soapenv:Envelope> There are some differences between how ‘Add Service Reference’ and the svcutil.exe generate the proxy class, but turns out both do some kind of reflection and determine the type of the data contract and emit the code accordingly. So since the Employee type is a class, the proxy ‘Person’ type gets generated as a class. In fact, reflecting on svcutil.exe application, you’ll see that there are a couple of places wherein a flag actually determines a type as a class or a struct. One example is in the ExportISerializableDataContract method in the System.Runtime.Serialization.CodeExporter class. Seems like these flags have a say in deciding whether the type gets emitted as a struct or a class. This behavior is different if you use the WSDL tool though. WSDL tool does not do any kind of reflection of the data contract / serialized type, it emits the type as a class by default. You can check this using the two command lines below:   Note to self: Remember ‘state’ and type-interchangeability when traversing through the WSDL planet!

    Read the article

  • DataContractSerializer case-insensitive datamember bug

    - by Andrew Bullock
    Here is my class: [DataContract] public class EventIndex : IExtensibleDataObject { public ExtensionDataObject ExtensionData { get; set; } [DataMember] private readonly IList<EventDescription> events; public IEnumerable<EventDescription> Events { get { return events; } } public EventIndex() { events = new List<EventDescription>(); } } As you can see, events is marked as a member. When I try and deserialize one of these classes, ReadObject throws a NullReferenceException. After a morning spent inside reflector, it turns out that its trying to deserialize the events collection into the Events getter. If I rename one of the members (events\ Events) I don't have an issue. Is there a way to make this work properly, without renaming workarounds or other such nonsense?

    Read the article

  • Adding WCF service reference adds DataContract types too

    - by Avi Shilon
    Hi everybody, I've used Visual Studio's Add Service Reference feature to add a service (actually it is a workflow service, created in WF4 RC1, but I don't think this makes any difference), and it also added the DataContracts that the service uses. At first this seemed fine, because All I've had in the DataContracts was simply properties, with no implementations. But now I've added code in the constructor of one data contracts that initializes creates an instance of one of the properties that exposes a list of other DCs, and when I've updated the service reference via VS (2010 RC1), the implementation was not updated. What should I do? Should I use my DCs instead of the ones created by VS or should I use the ones VS created? I've noticed that the properties in the VS-generated DCs contain some additional logic for checking equality in the setters and they also implement some interfaces too (like IExtensibleDataObject and INotifyPropertyChanged) which might get handy I guess in the future (I'm not knowledgeable at WCF). Thank you for your time folks, Avi

    Read the article

  • Do I have to worry about escaping XML reserved characters before I return a DataContract object from

    - by Brett Widmeier
    Hi, I am pretty inexperienced with WCF. I have a DataContract that implements the IExtensibleDataObject interface. Some of the members of this object are populated from freetext input and could contain XML reserved characters ('', for example). I imagine that I get escaping of these characters for free with WCF, but I have been looking around and could not find anything commenting on this one way or another. Is this the case? I have set my service to log the messages that it sends and receives for viewing in the Trace Viewer. Part of a message that my service returns looks like this: <sInstructions>"></sInstructions> Now, I have a couple questions about this. 1) Is it actually transmitting "&gt; and just showing it in a more readable form in the trace viewer? 2) If it is actually is transmitting ">, is this legal XML?

    Read the article

  • Problem with serialization of svcutil synthetized classes

    - by user295502
    I used svcutil to generate classes to access the web service. I need to serialize them. The class is quite simple, here is how it looks [System.Diagnostics.DebuggerStepThroughAttribute()] [System.CodeDom.Compiler.GeneratedCodeAttribute("System.Runtime.Serialization", "3.0.0.0")] [System.Runtime.Serialization.DataContractAttribute(Name="cosemAttributeDescriptor", Namespace="http://www.energiened.nl/Content/Publications/dsmr/P32")] public partial class cosemAttributeDescriptor : object, System.Runtime.Serialization.IExtensibleDataObject { private System.Runtime.Serialization.ExtensionDataObject extensionDataField; private ushort ClassIdField; private string InstanceIdField; private sbyte AttributeIdField; public System.Runtime.Serialization.ExtensionDataObject ExtensionData { get { return this.extensionDataField; } set { this.extensionDataField = value; } } [System.Runtime.Serialization.DataMemberAttribute(IsRequired=true)] public ushort ClassId { get { return this.ClassIdField; } set { this.ClassIdField = value; } } [System.Runtime.Serialization.DataMemberAttribute(IsRequired=true, EmitDefaultValue=false)] public string InstanceId { get { return this.InstanceIdField; } set { this.InstanceIdField = value; } } [System.Runtime.Serialization.DataMemberAttribute(IsRequired=true, Order=2)] public sbyte AttributeId { get { return this.AttributeIdField; } set { this.AttributeIdField = value; } } } Now, the problem is I can't serialize the class. Here is the serialization code: cosemAttributeDescriptor cAttrD = new cosemAttributeDescriptor(); cAttrD.ClassId = 3; cAttrD.InstanceId = "0100010800FF"; cAttrD.AttributeId = 0; DataContractSerializer dSer = new DataContractSerializer(typeof(cosemAttributeDescriptor)); StringBuilder sb = new StringBuilder(); XmlWriter xW = XmlWriter.Create(sb); dSer.WriteObject(xW, cAttrD); When I try to serialize the class, I get empty string. Any thoughts?

    Read the article

  • Recommendations, Asp.Net ObjectDataSource bind result of webservice call

    - by DerDres
    I need recommendations on how to solve / structure a solution to the following problem. In an asp.net web application i'll have to visualise results returned from a web service call. Im planning to use a repeater server control and bind this with an objectdatasource. The service returns a result of the form: public class SearchResult : IExtensibleDataObject { [DataMember] public Guid SearchId { get; set; } [DataMember] public DateTime Timestamp { get; set; } [DataMember] public int Offset { get; set; } [DataMember] public int TotalResults { get; set; } [DataMember] public IList<ResultDocumentData> Documents { get; set; } It is the collection of Documents that I need to visualise with a repeater which will be associated with an ObjectDataSource. The datasource should work on the type ResultDocumentData; the collection property in the class SearchResult. I think I need to wrap the call to the webservice in a dataaccess layer class, that will have a getDocuments method returning an IList, that the ObjectDataSource can use as its SelectMethod. I think I could make this work, but I would like to know how to do it in an elegant way. Can you give me general recommendations and/or recommendations for the following: WebProject Folderstructure + naming Naming conventions for the name of the service wrapper class Creating the service reference

    Read the article

1