简体   繁体   中英

WCF Service Empty Response

I have implemented WCF SOAP service that, according to debugger is working fine. Nevertheless, I am not receiving any response in Postman or SOAP UI.

My ServiceContract function is returning Message object as it should:

        public Message ReceiveMessage(Message message)
        {
            OTA.OTA_HotelResNotifRQ bodyObject;

            using (System.Xml.XmlDictionaryReader reader = message.GetReaderAtBodyContents())
            {
                string content = reader.ReadOuterXml();
                StringReader bodyText = new StringReader(content);
                XmlSerializer bodySerializer = new XmlSerializer(typeof(OTA.OTA_HotelResNotifRQ));
                bodyObject = (OTA.OTA_HotelResNotifRQ)bodySerializer.Deserialize(bodyText);
            }

            OTA.OTA_HotelResNotifRS rs = new OTA.OTA_HotelResNotifRS
            {
                Version = 1,
                EchoToken = bodyObject.EchoToken,
                TimeStamp = DateTime.Now,
                Items = new object[] { new OTA.SuccessType() }
            };

            Message rsMessage = Message.CreateMessage(message.Version, "ReceiveMessageResponse", rs);

            return rsMessage;
        }

OTA.OTA_HotelResNotifRS is serializable object created by xsd.exe (I have checked and serialization is working fine).

I don't get any error, just no response.

Any idea?

Edit:

Yes there was a problem with serialization:

Type 'OTA.SuccessType' with data contract name >'SuccessType: http://schemas.datacontract.org/2004/07/OTA ' is not expected. >Consider using a DataContractResolver if you are using DataContractSerializer or >add any types not known statically to the list of known types - for example, by >using the KnownTypeAttribute attribute or by adding them to the list of known >types passed to the serializer.

Problem is obviously in this:

        [System.Xml.Serialization.XmlElementAttribute("Errors", typeof(ErrorsType))]
        [System.Xml.Serialization.XmlElementAttribute("Success", typeof(SuccessType))]
        [System.Xml.Serialization.XmlElementAttribute("Warnings", typeof(WarningsType))]
        public object[] Items
        {
            get { return this.itemsField; }
            set { this.itemsField = value; }
        }

I don't know how should I apply KnownTypeAtribute as this is not a class.

I gave up and serialized response object (object that should go to Body) by XmlSerializer which knows how to do that.

XmlReader respXML;
using (StringWriter respWriter = new StringWriter())
{
    XmlSerializer respSerializer = new XmlSerializer(typeof(OTA.OTA_HotelResNotifRS));
    respSerializer.Serialize(respWriter, rs);           // rs is my response object
    string resp = respWriter.ToString().Remove(0, 41);  // just to remove <?xml version="1.0" encoding="utf-8" ?> on the top of produced string
    respXML = XmlReader.Create(new StringReader(resp)); // finally, XmlReader has my body element
}

Message rsMessage = Message.CreateMessage(message.Version, "ReceiveMessageResponse", respXML);
return rsMessage;

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM