简体   繁体   English

WCF-通过REST使用XMI

[英]WCF - comsume XMI over REST

I am trying to consume a rest service which returns XMI data like this: 我正在尝试使用Rest服务,该服务返回如下XMI数据:

<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. 无法反序列化具有根名称“ XMI”和根名称空间“ http://www.omg.org/XMI”的XML主体(用于操作“ MyMethod”和合同(“ IMyService”,“ http://tempuri.org/” ))使用XmlSerializer。 Ensure that the type corresponding to the XML is added to the known types collection of the service. 确保将与XML对应的类型添加到服务的已知类型集合中。

Anyone any ideas? 有任何想法吗? (I am able to consume other REST services without namespaces) (我能够使用其他没有名称空间的REST服务)

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM