Rails compatible .NET xml serialization -


I am writing an ASP.NET MVC2 site with the rest overpoint. I want to consume this service with ActiveResource in a Rail web application.

So far, I have established a route setup in ASP.NET MVC which matches the ActiveResource conventions. But where I'm having trouble, that data is with D-serial which sends ActiveResource to REST service.

It seems that the rail XML array is very different from the NAT (but I am not able to document these conventions anywhere). For example, with a .NET class like this:

  public class person {public string first_name {get; Set; } Public string last_name {get; Set; } Public Bull Active {get; Set; }}  

Here are some differences:

  1. As root net & lt; Person> Rails & lt; Person>
  2. .NET adds a namespace, while the rail does not
  3. Sorts the .NET properties such as & lt; First_name> Rails & lt; Firstname>
  4. As the .NET Serial Bull & lt; Active> Rails & lt; No. 4 does not seem to be the cause of any problem, but the other 3 reasons not to the .NET-SERIAL message allows you to decorate the object with XmlRoot and XmlElement attributes. By solving these problems can happen. But this error is prone and tedious.

    Does anyone know better about d-serial NARL which has been serialized by Rail 'Active Resource'?

can be obtained by using it.

The following is a basic example, GetOverrides () Important part:

  Public class RailsXmlSerializer {Private type type; Public RailsXmlSerializer (type type) {this.type = type; } Public Zero Serialize (Stream Stream, Object O) {XmlSerializerNamespaces ns = new XmlSerializerNamespaces (); Ns.Add ("", ""); XmlSerializer xmlSerializer = New XmlSerializer (type, GetOverrides (type)); XmlSerializer.Serialize (stream, o, ns); } Public Object Deserialize (stream stream) {XmlSerializer xmlSerializer = New XmlSerializer (type, GetOverrides (type)); Return xmlSerializer Direialize (stream); } Private XmlAttributeOverrides GetOverrides (Type Type) {XmlAttributeOverrides Override = New XmlAttributeOverrides (); XMLTVS class entitlements = new XLL properties (); ClassAttributes.XmlType = New XmlTypeAttribute (type.Name.ToLower ()); Overrides.Add (type, square properties); PropertyDescriptor property in foreign currency (TypeDescriptor.GetProperties (type)) {XmlAttributes propertyAttributes = new XmlAttributes (); Change PropertyAttributes.XmlElements.Add (New XmlElementAttribute (property.Name.ToLower (). Change ('_', '-'))); Overrides.Add (type, property.Name, attribute properties); } Override return; }}  

Obviously, this should be a more effective implementation, possibly as a decorator, with error and type inquiry. Of course, GetOverrides () can also be customized to provide the specific output you want. It is being said that, here is a sample person object:

   

Comments

Popular posts from this blog

sql - dynamically varied number of conditions in the 'where' statement using LINQ -

asp.net mvc - Dynamically Generated Ajax.BeginForm -

Debug on symbian -