Issue with GET and custom mediatypeprocessors

Topics: Web Api
Mar 8, 2011 at 9:35 PM

Hi all,

Hopefully this will be a simple issue but it has me stumped.

I have a custom mediatypeprocessor that serializes/deserializes data using DataContractSerializer to handle XML processing. Here is the relevant code:

        public override IEnumerable<string> SupportedMediaTypes
        {
            get { return new List<string> { "text/xml""application/xml" }; }
        }

 

        public override object ReadFromStream(Stream stream, HttpRequestMessage request)
        {
            var serializer = new DataContractSerializer(Parameter.ParameterType);
            return serializer.ReadObject(stream);
        }

Now, the deserializer works when I call it with "PUT" and a payload. Which inserts a record in the database. (The URI is "http://<service>/Flow")

I can then retrieve this record in a browser through a GET call. In this case, the MediaType is "text/plain" so the above code is not hit. (The template is "http://<service>/Flow/{id}")

However, when I try to retrieve the same call through a WCF client, the MediaType is now set to "application/xml". The ReadFromStream is called, however the Parameter value is NULL, so an exception is thrown.

How can I get the Parameter value to be populated? Your help will be greatly appreciated.

Thank you