Note: Forums will be making significant UX changes to address key usability improvements surrounding search, discoverability and navigation. To learn more about these changes please visit the announcement which can be found HERE.
WCF Service deployed using DataContractSerilizer - how to use XMLSerializer in DeserializeRequest

Answered WCF Service deployed using DataContractSerilizer - how to use XMLSerializer in DeserializeRequest

  • Wednesday, April 11, 2012 9:10 PM
     
     

    I have a WCF service deployed using the DataContract Serializer.  Clients can send request in Json or XML.  I created a IDispatchMessageFormatter.   I would like to use the XMLSerializer when serializing request that are "application/xml".  Otherwise I would use the data contract serializer to handle JSON.  

    How do I go about implementing the DeserializeRequest method so I can use the XMLSerializer to serialize the data stream into my object?  And also parse the HTTP query parameters?

    [WebInvoke(Method = "POST", UriTemplate = "customer/{customerId}")]
    void CreateCustomer(string customerId, Customer customer);

        public void DeserializeRequest(System.ServiceModel.Channels.Message message, object[] parameters)
    {
    // How to implement.
    }

    Error I receive.

    Unable to deserialize XML body with root name 'Customer' and root namespace '' using DataContractSerializer. Ensure that the type corresponding to the XML is added to the known types collection of the service.

    Thanks

All Replies