WCF - consumir XMI sobre REST

I am trying to consume a rest service which returns XMI data like this:

<xmi:XMI xmlns:xmi="http://www.omg.org/XMI" xmi:version="2.0">
...
</...>

I want to consume this in a service contract like this:

[ServiceContract]
[XmlSerializerFormat]
interface IMyService
{

    [OperationContract]
    [WebGet(
        BodyStyle = WebMessageBodyStyle.Bare,
        ResponseFormat = WebMessageFormat.Xml,
        UriTemplate = "myMethod")]
    MyData MyMethod();

...

}

My data contract looks like this (empty for testing):

[DataContract]
[XmlRoot]
public class MyData
{
}

Obtengo la siguiente excepción:

Unable to deserialize XML body with root name 'XMI' and root namespace 'http://www.omg.org/XMI' (for operation 'MyMethod' and contract ('IMyService', 'http://tempuri.org/')) using XmlSerializer. Ensure that the type corresponding to the XML is added to the known types collection of the service.

Anyone any ideas? (I am able to consume other REST services without namespaces)

preguntado el 09 de marzo de 12 a las 13:03

1 Respuestas

Ok, found the answer myself: You have to specify the namespace and root element name:

[XmlRoot(Namespace = "http://www.omg.org/XMI", ElementName = "XMI")]
public class MyData
{
}

respondido 10 mar '12, 11:03

No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas or haz tu propia pregunta.