使用新命名空间自定义OData xml

时间:2011-11-07 09:26:55

标签: .net wcf-data-services odata

我正在使用WCF数据服务。

我的OData服务中的实体的默认Feed属性是

<feed xml:base="http://localhost:54527/DataModel.svc/" xmlns:d="http://schemas.microsoft.com/ado/2007/08/dataservices" xmlns:m="http://schemas.microsoft.com/ado/2007/08/dataservices/metadata" xmlns="http://www.w3.org/2005/Atom">

如何在Feed属性中将自己的名称空间添加到此列表?

我正在努力使我的odata服务与GeoRSS兼容,我添加了一些EntityPropertyMappingAttribute以使数据兼容,但我们正在使用的工具无法识别它。

现在正在制作这个:

    <?xml version="1.0" encoding="iso-8859-1" standalone="yes"?>
<feed xml:base="http://localhost:54527/DataModel.svc/" xmlns:d="http://schemas.microsoft.com/ado/2007/08/dataservices" xmlns:m="http://schemas.microsoft.com/ado/2007/08/dataservices/metadata" xmlns="http://www.w3.org/2005/Atom">
  <title type="text">Collars</title>
  <id>http://localhost:54527/DataModel.svc/Collars</id>
  <updated>2011-11-07T09:23:05Z</updated>
  <link rel="self" title="Collars" href="Collars" />
  <entry>
    <id>http://localhost:54527/DataModel.svc/Collars(HOLEID='ABL001',PROJECTCODE='ACA')</id>
    <title type="text"></title>
    <updated>2011-11-07T09:23:05Z</updated>
    <author>
      <name />
    </author>
    <link rel="edit" title="Collar" href="Collars(HOLEID='ABL001',PROJECTCODE='ACA')" />
    <category term="Neo.Collar" scheme="http://schemas.microsoft.com/ado/2007/08/dataservices/scheme" />
    <content type="application/xml">
      <m:properties>
        <d:HOLEID>ABL001</d:HOLEID>
        <d:PROJECTCODE>ACA</d:PROJECTCODE>
        <d:TENEMENTID>5853</d:TENEMENTID>
        <d:LAT>116.49531406</d:LAT>
        <d:LONG>-21.65159678</d:LONG>
      </m:properties>
    </content>
    <geo:lat xmlns:geo="http://www.georss.org/georss">116.49531406</geo:lat>
    <geo:long xmlns:geo="http://www.georss.org/georss">-21.65159678</geo:long>
  </entry>

但我宁愿让地理名称空间位于顶部:

    <?xml version="1.0" encoding="iso-8859-1" standalone="yes"?>
<feed xml:base="http://localhost:54527/DataModel.svc/" xmlns:d="http://schemas.microsoft.com/ado/2007/08/dataservices" xmlns:m="http://schemas.microsoft.com/ado/2007/08/dataservices/metadata" xmlns="http://www.w3.org/2005/Atom"
xmlns:geo="http://www.georss.org/georss">
  <title type="text">Collars</title>
  <id>http://localhost:54527/DataModel.svc/Collars</id>
  <updated>2011-11-07T09:23:05Z</updated>
  <link rel="self" title="Collars" href="Collars" />
  <entry>
    <id>http://localhost:54527/DataModel.svc/Collars(HOLEID='ABL001',PROJECTCODE='ACA')</id>
    <title type="text"></title>
    <updated>2011-11-07T09:23:05Z</updated>
    <author>
      <name />
    </author>
    <link rel="edit" title="Collar" href="Collars(HOLEID='ABL001',PROJECTCODE='ACA')" />
    <category term="Neo.Collar" scheme="http://schemas.microsoft.com/ado/2007/08/dataservices/scheme" />
    <content type="application/xml">
      <m:properties>
        <d:HOLEID>ABL001</d:HOLEID>
        <d:PROJECTCODE>ACA</d:PROJECTCODE>
        <d:TENEMENTID>5853</d:TENEMENTID>
        <d:LAT>116.49531406</d:LAT>
        <d:LONG>-21.65159678</d:LONG>
      </m:properties>
    </content>
    <geo:lat>116.49531406</geo:lat>
    <geo:long>-21.65159678</geo:long>
  </entry>

我可能会以完全错误的方式解决这个问题。 感谢。

1 个答案:

答案 0 :(得分:0)

目前,WCF数据服务无法做到这一点。实体属性映射在本地工作(在它映射到的元素上),它没有能力指定应该预先声明某些命名空间。