Thursday, 25 December 2014

WCF deserialization



Please help me out to get this fixed... Its been ages I'm trying to solve this.


I'm writing a wcf service which consumes a third party service as service reference. And this wcf service will be used in a client to send soap xml messages.


While using xml serializer the client code to deserialize an xml file works but some of the properties are null; which worked while using a asmx web service. Please let me know if I'm missing something.


The wcf service is below,



[ServiceBehavior(Namespace = "http://ift.tt/1t4ji3D")]
[SoapDocumentService(ParameterStyle=SoapParameterStyle.Bare)]
public class Service : IService
{
[SoapDocumentMethod(ParameterStyle=SoapParameterStyle.Bare)]
public OTA_HotelResNotifRS ReservationNotification(OTA_HotelResNotifRQ OTA_HotelResNotifRQ)
{
...........
}

[ServiceContract(Namespace = "http://ift.tt/1t4ji3D")]
[XmlSerializerFormat]
public interface IService
{
[OperationContract (Action="http://ift.tt/1EncbgQ")]
[return: MessageParameter(Name = "OTA_HotelResNotifRS")]
OTA_HotelResNotifRS ReservationNotification(OTA_HotelResNotifRQ OTA_HotelResNotifRQ);

}


The client code is below



LotusResNotifService.OTA_HotelResNotifRQ OTA_HotelResNotifRQ = new LotusResNotifService.OTA_HotelResNotifRQ();

XmlRootAttribute xRoot = new XmlRootAttribute();
xRoot.ElementName = "OTA_HotelResNotifRQ";
xRoot.IsNullable = true;
xRoot.Namespace = "http://ift.tt/NpIDks";

XmlSerializer deserializer = new XmlSerializer(OTA_HotelResNotifRQ.GetType(), xRoot);
StreamReader reader = new StreamReader(@"D:\HotelResNotifRQ_SOAP_RQ.xml");
object deserialized = deserializer.Deserialize(reader.BaseStream);
OTA_HotelResNotifRQ = (LotusResNotifService.OTA_HotelResNotifRQ)deserialized;


The OTA_HotelResNotifRQ has some of the properties returned as null though the xml elements and values are present...


No comments:

Post a Comment