How to get raw XML in a WCF client from a web service

I have a WCF client (console application) that calls the WCF web service, and I'm trying to get the original XML response from my console application.

Does anyone have an idea or code snippet on how to do this?

+5
source share
2 answers

You can use the client message inspector

See link

In your own, BeforeSendRequestyou can simply call ToString () in the message.

+3
source

I was able to get the original xml using this method:

string _serial = SerializeObj(retVal);

public string SerializeObj<T>(T obj)
        {
            XmlSerializer xmlSerializer = new XmlSerializer(obj.GetType());

            using (StringWriter txtWriter= new StringWriter())
            {
                xmlSerializer.Serialize(txtWriter, obj);
                return txtWriter.ToString();
            }
        }
-2
source

All Articles