WCF配信サービスライブラリをIISでホスト

投稿日 : 2008年4月7日 22:12

 Visual Studio 2008のプロジェクトのテンプレート「WCFの配信サービスライブラリ」は、プロジェクトを作成した時点でRSSおよびAtomフィードを配信するサービスができています。実行するとテスト用のWCFサービスホスト(WcfSvcHost.exe) が起動しサービスをホストしてくれます。これじゃ不便なときがあるのでIISでホストできるように設定してみます。

 WCF配信サービスライブラリのプロジェクト名は「SyndicationSample」として進めます。1度はビルドしておきましょう。

 まずは、ソリューションにプロジェクトを新規にWCFサービスアプリケーションプロジェクトを追加します。新しいプロジェクトウィンドウからWebのWCFサービスアプリケーションを選びます。プロジェクト名は「WcfServiceSample」にしました。

 追加したら配信サービスライブラリプロジェクトへの参照を追加します。ソリューションエクスプローラのプロジェクト名を右クリックして、参照の追加を選択します。プロジェクトタブからSyndicationSampleを選びます。

 次にソリューションエクスプローラからWeb.configを右クリックしてEdit WCF Configurationを選択して、WCF Service Configuration Editorを起動します。

ソリューションエクスプローラ

 EditorのConfigurationペインからServicesを選択して、右のペインの「Create a New Service」をクリックします。Browseボタンをクリックして配信サービスライブラリをビルドしてできたSyndicationSample.dllを選択します。OpenボタンをクリックするとSyndicationSample.Feed1とさらにアイテムが表示されるので、それを選択してOpenボタンをクリックします。

サービスの作成

 Nextをクリックして進めます。次の画面からは「SyndicationSample.IFeed1」、「HTTP」、「Basic Web Services interoperability」を選択して進めます。Addressの設定画面では空白にします。以上でFinishボタンが有効になりクリックして完了です。

 左ペインから追加されたSyndicationSample.Feed1-Endpoints-(Empty Name)を選択して、右ペインからBinding項目のbasicHttpBindingをwebHttpBindingへ変更します。

Service Endpointの設定

 続いてAdvancedのEndpoint Behaviorsを選択し、右ペインの「New Endpoint Behavior Configuration」をクリックして新しいBehavior要素を作成します。左ペインにNewBehaviorという項目が追加されるので、それを選択します。右ペインのAddボタンをクリックしてwebHttpを選び、追加します。

Behaviorの追加

 SyndicationSample.Feed1-Endpoints-(Empty Name)に戻ります。BehaviorConfiguration項目にNewBehaviorが選択できるようになっているので選択します。以上で設定は完了です。Ctrl+Sで上書き保存してEditorを終了します。

 ソリューションエクスプローラからService1.svcを右クリックしてマークアップの表示を選びます。そしてコードを次のように変更します。

<%@ ServiceHost Language="VB" Debug="true" Service="SyndicationSample.Feed1" %>

 ここで一度Service1.svcをブラウザで表示してみましょう。Service1.svcを右クリックして「ブラウザで表示」を選びます。特にエラーっぽいものがでなければOK。アドレスを「http://localhost:60464/Service1.svc/Feed1」のようにFeed1を付けるとフィードが表示されると思います。

 ここまできたら あと少しです。プロジェクト名を右クリックしてメニューから発行を選択します。「...」ボタンで「Webサイトを開く」ウィンドウを開き、ローカルIISの選び、Webサイトの場所を決定します。最後に発行ボタンをクリックします。

Webの発行

 以上で、http://localhost/sample/Service1.svc/Feed1 のように指定したアドレスにService1.svc/Feed1を付けてアクセスできるはずです。エラーになる場合はそもそもサービスが起動しているか、アクセス許可がないなど適当に対応しましょう。

フィードの表示

参考・お役立ちリンク

フィードバック

# Virtual Earth 開発環境

2008/04/16 23:19 by katamari.wankuma.com
Virtual Earth 開発環境

# WCF配信サービスライブラリをIISでホスト トラブル

2008/09/26 19:19 by katamari.wankuma.com
WCF配信サービスライブラリをIISでホスト トラブル

# WCF Service Configration Editor????????????????????? &laquo; istb16 blog

2010/10/07 23:47 by Pingback/TrackBack
WCF Service Configration Editor????????????????????? &laquo; istb16 blog

# It's going to be ending of mine day, except before finish I am reading this wonderful paragraph to increase my know-how.

2019/05/07 3:31 by It's going to be ending of mine day, except before
It's going to be ending of mine day, except before finish I
am reading this wonderful paragraph to increase my know-how.

# This is my first time pay a visit at here and i am truly impressed to read everthing at alone place.

2019/08/13 17:35 by This is my first time pay a visit at here and i am
This is my first time pay a visit at here and i am truly impressed to read everthing at alone place.

# My brother suggested I might like this blog. He was entirely right. This post actually made my day. You cann't imagine simply how much time I had spent for this info! Thanks!

2019/08/24 15:36 by My brother suggested I might like this blog. He wa
My brother suggested I might like this blog. He was entirely right.
This post actually made my day. You cann't imagine simply how much time I had spent for this info!
Thanks!

# These are truly enormous ideas in on the topic of blogging. You have touched some pleasant factors here. Any way keep up wrinting.

2023/09/01 13:17 by These are truly enormous ideas in on the topic of
These are truly enormous ideas in on the topic of blogging.
You have touched some pleasant factors here. Any way keep up wrinting.

# These are truly enormous ideas in on the topic of blogging. You have touched some pleasant factors here. Any way keep up wrinting.

2023/09/01 13:20 by These are truly enormous ideas in on the topic of
These are truly enormous ideas in on the topic of blogging.
You have touched some pleasant factors here. Any way keep up wrinting.

# These are truly enormous ideas in on the topic of blogging. You have touched some pleasant factors here. Any way keep up wrinting.

2023/09/01 13:22 by These are truly enormous ideas in on the topic of
These are truly enormous ideas in on the topic of blogging.
You have touched some pleasant factors here. Any way keep up wrinting.
コメントの入力
タイトル
 
名前
 
Url
コメント