Aquí dejo un ejemplo de código que muestra como cambiar el valor del atributo [XmlIgnore] en tiempo de ejecución para evitar que se serialicen campos a nuestra conveniencia. public class Person { [XmlIgnore] public string Name { get; set; } [XmlIgnore] public int Age { get; set; } } class   Read More ...

Categories: Uncategorized

Los servicios web de ASP.NET tienen eso, que cuando quieres devolver tu objeto Person te lo renombran al nombre del método + result y te lo meten dentro de un método + response, así este código: public class Person { public string Name { get; set; } }   [WebService(Namespace   Read More ...

Categories: Uncategorized

Aquí dejo un código de ejemplo para ignorar campos en tiempo de ejecución. La clave es crear un método llamado ShouldSerialized mas el nombre del campo. public class ClassWithNullableElements {   private Nullable<System.DateTime> endField;   private Nullable<System.DateTime> startField;   [System.Xml.Serialization.XmlAttributeAttribute(DataType = "date", AttributeName = "End")] public DateTime EndSerialized { get   Read More ...

Categories: Uncategorized

Aquí dejo una clase para hacer las serializaciones, la única dependencia es la librería Json.NET public class Serializer { public enum Format { json,xml } public static string Serialize(object data, Format format) { if (format == Format.json) return JsonConvert.SerializeObject(data); else { using (StringWriter sw = new StringWriter()) { XmlSerializer ser   Read More ...

Categories: Uncategorized

Aquí dejo un ejemplo de como usar MVC para hacer servicios rest utilizando diferentes formatos para transportar los datos, para la serializacion Json utilizo la librería Json.NET, es la única dependencia. Las url de los servicios de este ejemplo serán estas: http://localhost/RestServices/MyClass/All.json http://localhost/RestServices/MyClass/All.xml http://localhost/RestServices/MyClass/Get/1.json http://localhost/RestServices/MyClass/Get/1.xml http://localhost/RestServices/MyClass/GetByName/Nombre%201.json http://localhost/RestServices/MyClass/GetByName/Nombre%201.xml http://localhost/RestServices/MyClass/Put.json http://localhost/RestServices/MyClass/Put.xml http://localhost/RestServices/MyClass/Delete.json   Read More ...

Categories: Uncategorized

Mas de mi servicio "impersonal" … Resulta que ahora también recibe documentos SOAP, así que tengo que extraer los datos del mensaje SOAP con este código: private XmlDocument GetSOAPBody(XmlDocument xmlSoap) { const string SOAP_NAMESPACE = "http://schemas.xmlsoap.org/soap/envelope/"; XmlNodeList nodes = xmlSoap.GetElementsByTagName("Body", SOAP_NAMESPACE); if (nodes.Count == 0) return xmlSoap; XmlElement body =   Read More ...

Categories: Uncategorized

Aquí dejo una clase para consumir servicios web vía SOAP en los que no tengamos el WSDL o que el Wizard nos de problemas: using System; using System.Text; using System.IO; using System.Net; using System.Xml; namespace Test { class SOAPClient { public static XmlDocument SendMsg(XmlDocument xmlRQ) { byte[] byte1; Stream myStream;   Read More ...

Categories: Uncategorized

PUBLICIDAD

EMAIL





posts recientes

MapReduce con MongoDB

Posted on may - 18 - 2012

0 Comment

Habilitar la compresión de...

Posted on abr - 25 - 2012

0 Comment

Bamboo, MSBuild y referencias...

Posted on abr - 17 - 2012

2 Comments

Sponsors

  • Etooltech
  • Dingus Services
  • Etooltech
  • Dingus Services