Share via


WCF 配信オブジェクト モデルを Atom や RSS に割り当てる方法

Windows Communication Foundation (WCF) 配信サービスを開発する場合、次のクラスを使用するフィードや項目を作成します。

SyndicationFeed はフォーマッタが定義されている任意の配信フォーマットにシリアル化できます。WCF には、Atom10FeedFormatter および Rss20FeedFormatter の 2 つのフォーマッタが付属しています。

RSS 2.0 仕様より Atom 1.0 仕様の方が、SyndicationFeed および SyndicationItem 周辺のオブジェクト モデルをより細かく調整しています。これは、Atom 1.0 が、あいまいな要素または RSS 2.0 仕様から省略された要素を定義する、より基本的な仕様であるためです。このため、WCF 配信オブジェクト モデルにある多くの項目には、RSS 2.0 仕様の直接表現がありません。SyndicationFeed および SyndicationItem オブジェクトを RSS 2.0 にシリアル化する場合、WCF により、Atom 固有のデータ要素を、Atom 仕様に準拠する名前空間で修飾された拡張要素にシリアル化できます。これは、Rss20FeedFormatter コンストラクタに渡すパラメータで制御できます。

このトピックのコード例では、ここで定義される 2 つのメソッドのいずれかを使い、実際のシリアル化を行っています。

SerializeFeed は、配信フィードをシリアル化します。

SerializeItem は、配信項目をシリアル化します。

SyndicationFeed

SyndicationFeed クラスを Atom 1.0 および RSS 2.0 にシリアル化するコード例を次に示します。

次の XML は、SyndicationFeed を Atom 1.0 にシリアル化する方法を示しています。

<?xml version="1.0" encoding="utf-8"?>
<feed xml:lang="EN-US" xmlns="http://www.w3.org/2005/Atom">
  <title type="text">My Feed Title</title>
  <subtitle type="text">My Feed Description</subtitle>
  <id>FeedID</id>
  <rights type="text">Copyright 2007</rights>
  <updated>2007-08-29T13:57:17-07:00</updated>
  <category term="categoryName" label="categoryLabel" scheme="categoryScheme" />
  <logo>https://server/image.jpg</logo>
  <generator>Sample Code</generator>
  <link rel="alternate" href="http://myfeeduri/" />
  <entry>
    <id>ItemID</id>
    <title type="text">Item Title</title>
    <summary type="text">Item Summary</summary>
    <published>2007-08-29T00:00:00-07:00</published>
    <updated>2007-08-29T13:57:17-07:00</updated>
    <author>
      <name>Jesper Aaberg</name>
      <uri>http://Jesper/Aaberg</uri>
      <email>Jesper@Aaberg.com</email>
    </author>
    <contributor>
      <name>Lene Aaling</name>
      <uri>http://Lene/Aaling</uri>
      <email>Lene@Aaling.com</email>
    </contributor>
    <link rel="alternate" href="http://myitemuri/" />
    <category term="categoryName" label="categoryLabel" scheme="categoryScheme" />
    <content type="text">Item Content</content>
    <rights type="text">Copyright 2007</rights>
    <source>
      <title type="text">My Feed Title</title>
      <subtitle type="text">My Feed Description</subtitle>
      <id>FeedID</id>
      <rights type="text">Copyright 2007</rights>
      <updated>2007-08-29T13:57:17-07:00</updated>
      <category term="categoryName" label="categoryLabel" scheme="categoryScheme" />
      <logo>https://server/image.jpg</logo>
      <generator>Sample Code</generator>
      <link rel="alternate" href="http://myfeeduri/" />
    </source>
  </entry>
</feed>

SyndicationFeed を RSS 2.0 にシリアル化する方法を次の XML に示します。

<?xml version="1.0" encoding="utf-8"?>
<rss xmlns:a10="http://www.w3.org/2005/Atom" version="2.0">
  <channel>
    <title>My Feed Title</title>
    <link>http://myfeeduri/</link>
    <description>My Feed Description</description>
    <language>EN-US</language>
    <copyright>Copyright 2007</copyright>
    <lastBuildDate>Wed, 29 Aug 2007 13:57:17 -0700</lastBuildDate>
    <category domain="categoryScheme">categoryName</category>
    <generator>Sample Code</generator>
    <image>
      <url>https://server/image.jpg</url>
      <title>My Feed Title</title>
      <link>http://myfeeduri/</link>
    </image>
    <a10:id>FeedID</a10:id>
    <item>
      <guid isPermaLink="false">ItemID</guid>
      <link>http://myitemuri/</link>
      <author>Jesper@Aaberg.com</author>
      <category domain="categoryScheme">categoryName</category>
      <title>Item Title</title>
      <description>Item Summary</description>
      <source>My Feed Title</source>
      <pubDate>Wed, 29 Aug 2007 00:00:00 -0700</pubDate>
      <a10:updated>2007-08-29T13:57:17-07:00</a10:updated>
      <a10:rights type="text">Copyright 2007</a10:rights>
      <a10:content type="text">Item Content</a10:content>
      <a10:contributor>
        <a10:name>Lene Aaling</a10:name>
        <a10:uri>http://Lene/Aaling</a10:uri>
        <a10:email>Lene@Aaling.com</a10:email>
      </a10:contributor>
    </item>
  </channel>
</rss>

SyndicationItem

SyndicationItem クラスを Atom 1.0 および RSS 2.0 にシリアル化するコード例を次に示します。

SyndicationItem を Atom 1.0 にシリアル化する方法を次の XML に示します。

<entry xmlns="http://www.w3.org/2005/Atom">
  <id>ItemID</id>
  <title type="text">Item Title</title>
  <summary type="text">Item Summary</summary>
  <published>2007-08-29T00:00:00-07:00</published>
  <updated>2007-08-29T14:07:09-07:00</updated>
  <author>
    <name>Jesper Aaberg</name>
    <uri>http://Contoso/Aaberg</uri>
    <email>Jesper.Aaberg@contoso.com</email>
  </author>
  <author>
    <name>Syed Abbas</name>
    <uri>http://Contoso/Abbas</uri>
    <email>Syed.Abbas@contoso.com</email>
  </author>
  <contributor>
    <name>Lene Aaling</name>
    <uri>http://Contoso/Aaling</uri>
    <email>Lene.Aaling@contoso.com</email>
  </contributor>
  <contributor>
    <name>Kim Abercrombie</name>
    <uri>http://Contoso/Abercrombie</uri>
    <email>Kim.Abercrombie@contoso.com</email>
  </contributor>
  <link rel="alternate" href="http://myitemuri/" />
  <category term="categoryName" label="categoryLabel" scheme="categoryScheme" />
  <category term="categoryName" label="categoryLabel" scheme="categoryScheme" />
  <content type="text">Item Content</content>
  <rights type="text">Copyright 2007</rights>
  <source>
    <title type="text">My Feed Title</title>
    <subtitle type="text">My Feed Description</subtitle>
    <link rel="alternate" href="http://myfeeduri/" />
  </source>
</entry>

SyndicationItem を RSS 2.0.0 にシリアル化する方法を次の XML に示します。

<item>
  <guid isPermaLink="false">ItemID</guid>
  <link>http://myitemuri/</link>
  <author xmlns="http://www.w3.org/2005/Atom">
    <name>Jesper Aaberg</name>
    <uri>http://Jesper/Aaberg</uri>
    <email>Jesper@Aaberg.com</email>
  </author>
  <author xmlns="http://www.w3.org/2005/Atom">
    <name>Syed Abbas</name>
    <uri>http://Contoso/Abbas</uri>
    <email>Syed.Abbas@contoso.com</email>
  </author>
  <category domain="categoryScheme">categoryName</category>
  <category domain="categoryScheme">categoryName</category>
  <title>Item Title</title>
  <description>Item Summary</description>
  <source>My Feed Title</source>
  <pubDate>Wed, 29 Aug 2007 00:00:00 -0700</pubDate>
  <updated xmlns="http://www.w3.org/2005/Atom">2007-08-29T14:07:09-07:00</updated>
  <rights type="text" xmlns="http://www.w3.org/2005/Atom">Copyright 2007</rights>
  <content type="text" xmlns="http://www.w3.org/2005/Atom">Item Content</content>
  <contributor xmlns="http://www.w3.org/2005/Atom">
    <name>Lene Aaling</name>
    <uri>http://Contoso/Aaling</uri>
    <email>Lene.Aaling@contoso.com</email>
  </contributor>
  <contributor xmlns="http://www.w3.org/2005/Atom">
    <name>Kim Abercrombie</name>
    <uri>http://Contoso/Abercrombie</uri>
    <email>Kim.Abercrombie@contoso.com</email>
  </contributor>
</item>

SyndicationPerson

SyndicationPerson クラスを Atom 1.0 および RSS 2.0 にシリアル化するコード例を次に示します。

SyndicationPerson を Atom 1.0 にシリアル化する方法を次の XML に示します。

  <author>
    <name>Jesper Aaberg</name>
    <uri>http://Contoso/Aaberg</uri>
    <email>Jesper.Aaberg@contoso.com</email>
  </author>
<contributor>
    <name>Lene Aaling</name>
    <uri>http://Contoso/Aaling</uri>
    <email>Lene.Aaling@contoso.com</email>
  </contributor>

Authors コレクションまたは Contributors コレクションに、それぞれ SyndicationPerson が 1 つのみ存在する場合に、SyndicationPerson クラスを RSS 2.0 にシリアル化する方法を次の XML に示します。

<author>Jesper.Aaberg@contoso.com</author>
<a10:contributor>
    <a10:name>Lene Aaling</a10:name>
    <a10:uri>http://Contoso/Aaling</a10:uri>
    <a10:email>Lene.Aaling@contoso.com</a10:email>
</a10:contributor>

Authors コレクションまたは Contributors コレクションに、それぞれ SyndicationPerson が複数存在する場合に、SyndicationPerson クラスを RSS 2.0 にシリアル化する方法を次の XML に示します。

<a10:author>
    <a10:name>Jesper Aaberg</a10:name>
    <a10:uri>http://Contoso/Aaberg</a10:uri>
    <a10:email>Jesper.Aaberg@contoso.com</a10:email>
</a10:author>
<a10:author>
    <a10:name>Syed Abbas</a10:name>
    <a10:uri>http://Contoso/Abbas</a10:uri>
    <a10:email>Syed.Abbas@contoso.com</a10:email>
</a10:author>
<a10:contributor>
    <a10:name>Lene Aaling</a10:name>
    <a10:uri>http://Contoso/Aaling</a10:uri>
    <a10:email>Lene.Aaling@contoso.com</a10:email>
</a10:contributor>
<a10:contributor>
    <a10:name>Kim Abercrombie</a10:name>
    <a10:uri>http://Contoso/Abercrombie</a10:uri>
    <a10:email>Kim.Abercrombie@contoso.com</a10:email>
</a10:contributor>

SyndicationLink クラスを Atom 1.0 および RSS 2.0 にシリアル化するコード例を次に示します。

SyndicationLink を Atom 1.0 にシリアル化する方法を次の XML に示します。

<link rel="alternate" type="text/html" title="My Link Title" length="2048" href="http://contoso/MyLink" />

SyndicationLink を RSS 2.0.0 にシリアル化する方法を次の XML に示します。

<a10:link rel="alternate" type="text/html" title="My Link Title" length="2048" href="http://contoso/MyLink" />

SyndicationCategory

SyndicationCategory クラスを Atom 1.0 および RSS 2.0 にシリアル化するコード例を次に示します。

SyndicationCategory を Atom 1.0 にシリアル化する方法を次の XML に示します。

<category term="categoryName" label="categoryLabel" scheme="categoryScheme" />

SyndicationCategory を RSS 2.0.0 にシリアル化する方法を次の XML に示します。

<category domain="categoryScheme">categoryName</category>

TextSyndicationContent

TextSyndicationContent が HTML コンテンツと共に作成される場合に TextSyndicationContent クラスを Atom 1.0 および RSS 2.0 にシリアル化するコード例を次に示します。

HTML コンテンツ付きの TextSyndicationContent クラスを Atom 1.0 にシリアル化する方法を次の XML に示します。

<content type="html">&lt;html&gt; some html &lt;/html&gt;</content>

HTML コンテンツ付きの TextSyndicationContent クラスを RSS 2.0 にシリアル化する方法を次の XML に示します。

<description>&lt;html&gt; some html &lt;/html&gt;</description>

TextSyndicationContent がプレーンテキスト コンテンツと共に作成される場合に、TextSyndicationContent クラスを Atom 1.0 および RSS 2.0 にシリアル化するコード例を次に示します。

プレーンテキスト コンテンツ付きの TextSyndicationContent クラスを Atom 1.0 にシリアル化する方法を次の XML に示します。

<content type="text">Some Plain Text</content>

プレーンテキスト コンテンツ付きの TextSyndicationContent クラスを RSS 2.0 にシリアル化する方法を次の XML に示します。

<description>Some Plain Text</description>

TextSyndicationContent が XHTML コンテンツと共に作成される場合に、TextSyndicationContent クラスを Atom 1.0 および RSS 2.0 にシリアル化するコード例を次に示します。

XHTML コンテンツ付きの TextSyndicationContent クラスを Atom 1.0 にシリアル化する方法を次の XML に示します。

<content type="xhtml">

<html> some xhtml </html>

</content>

XHTML コンテンツ付きの TextSyndicationContent クラスを RSS 2.0 にシリアル化する方法を次の XML に示します。

<description>&lt;html&gt; some xhtml &lt;/html&gt;</description>

UrlSyndicationContent

UrlSyndicationContent クラスを Atom 1.0 および RSS 2.0 にシリアル化するコード例を次に示します。

UrlSyndicationContent クラスを Atom 1.0 にシリアル化する方法を次の XML に示します。

<content type="audio" src="http://someurl/" />

XHTML コンテンツ付きの UrlSyndicationContent クラスを RSS 2.0 にシリアル化する方法を次の XML に示します。

<description />

<content type="audio" src="http://Contoso/someurl/" xmlns="http://www.w3.org/2005/Atom" />

XmlSyndicationContent

XmlSyndicationContent クラスを Atom 1.0 および RSS 2.0 にシリアル化するコード例を次に示します。

XmlSyndicationContent クラスを Atom 1.0 にシリアル化する方法を次の XML に示します。

<content type="mytype">

<SomeData xmlns:i="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://schemas.datacontract.org/2004/07/FeedMapping" />

</content>

XHTML コンテンツ付きの XmlSyndicationContent クラスを RSS 2.0 にシリアル化する方法を次の XML に示します。

<content type="mytype" xmlns="http://www.w3.org/2005/Atom">

<SomeData xmlns:i="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://schemas.datacontract.org/2004/07/FeedMapping" />

</content>

関連項目

タスク

方法 : 基本的な RSS フィードを作成する
方法 : 基本的な ATOM フィードを作成する
方法 : Atom および RSS の両方としてフィードを公開する

概念

WCF 配信の概要
配信のアーキテクチャ