简体   繁体   中英

WCF - comsume XMI over 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
{
}

I get the following exception:

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)

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
{
}

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