SHOEISHA iD

※旧SEメンバーシップ会員の方は、同じ登録情報(メールアドレス&パスワード)でログインいただけます

CodeZine編集部では、現場で活躍するデベロッパーをスターにするためのカンファレンス「Developers Summit」や、エンジニアの生きざまをブーストするためのイベント「Developers Boost」など、さまざまなカンファレンスを企画・運営しています。

Infragistics NetAdvantageチュートリアル(AD)

Silverlight/WPFでデータバインディングを利用しOutlookライクなスケジュールを構築する その3
WCF サービス 接続編

Silverlight/WPFでOutlookライクなアプリ構築(3)

  • このエントリーをはてなブックマークに追加

Silverlight アプリケーション ソリューションでサービスを使用

 xamSchedule_SL プロジェクトでサービスを使用する場合、参照設定から [サービス参照の追加] を選択します。先ほど作成したサービスが表示されますので、サービスの名前空間を "XamScheduleWCFService" とし、追加します。

図11 サービスの参照を追加
図11 サービスの参照を追加

 プロジェクトに ServiceReferences.ClientConfig ファイルが追加され、こちらに設定を記述することができます。この設定の中で、コントラクトを修正します。

コード3 ServiceReference.ClientConfig を修正
<configuration>
    <system.serviceModel>
        <bindings>
            <customBinding>
                <binding name="CustomBinding_IWcfListConnectorService">
                    <binaryMessageEncoding />
                    <httpTransport maxReceivedMessageSize="2147483647" maxBufferSize="2147483647" />
                </binding>
            </customBinding>
        </bindings>
        <client>
          <!-- contract をWcfListConnectorServiceSL.IWcfListConnectorServiceと設定 -->
            <endpoint address=http://localhost:2823/XamScheduleWCFService.svc
                binding="customBinding" bindingConfiguration="CustomBinding_IWcfListConnectorService"
                contract="WcfListConnectorServiceSL.IWcfListConnectorService"
                name="CustomBinding_IWcfListConnectorService" />
        </client>
    </system.serviceModel>
</configuration>

 次に、MainPage.xaml.cs を開き、その1で設定したコードによる予定追加部分を削除します。

コード4 MainPage.xaml.cs
using System.Windows.Controls;

namespace xamSchedule_SL
{
    public partial class MainPage : UserControl
    {
        public MainPage()
        {
            InitializeComponent();
        }
    }
}

 MainPage.xaml に追加されているコントロールをすべて削除し、新たに XamMonthView, XamScheduleDataManager, WcfListDataConnector を追加します。

コード5 MainPage.xaml
<UserControl x:Class="xamSchedule_SL.MainPage"
    xmlns=http://schemas.microsoft.com/winfx/2006/xaml/presentation
    xmlns:x=http://schemas.microsoft.com/winfx/2006/xaml
    xmlns:d=http://schemas.microsoft.com/expression/blend/2008
    xmlns:mc=http://schemas.openxmlformats.org/markup-compatibility/2006
    mc:Ignorable="d"
    d:DesignHeight="300" d:DesignWidth="400" 
    xmlns:ig="http://schemas.infragistics.com/xaml">
    <Grid>
        <ig:XamMonthView Name="xamMonthView1" />
        <ig:XamScheduleDataManager Name="xamScheduleDataManager1" />
        <ig:WcfListScheduleDataConnector Name="wcfListScheduleDataConnector1" />
    </Grid>
</UserControl>

 XamMonthView と XamScheduleDataManager を連結します。

コード6 DataManager の接続
<ig:XamMonthView Name="xamMonthView1" 
                    DataManager="{Binding ElementName=xamScheduleDataManager1}"/>

 XamScheduleDataManager と WcfListScheduleDataConnector を連結します。また、今回はリソース ID をあらかじめ定義しておきます。

コード7 DataConnector の接続
<ig:XamScheduleDataManager Name="xamScheduleDataManager1" 
                   DataConnector="{Binding ElementName=wcfListScheduleDataConnector1}"
                   CurrentUserId="R0001" />

 最後に WcfListScheduleDataConnector にエンドポイント設定名やデータ取得間隔を指定します。

コード8 コネクターの設定
<ig:WcfListScheduleDataConnector Name="wcfListScheduleDataConnector1" 
EndpointConfigurationName="CustomBinding_IWcfListConnectorService"
PollingInterval="00:00:30"
PollingMode="Detailed" />

 すべてが正しく設定されていると、実行時にDB からスケジュールデータを取得し、表示することが可能になります。

図12 データ ベースのスケジュール データを表示
図12 データ ベースのスケジュール データを表示

まとめ

 今回は WCF サービスを構築し、データ ベースからスケジュールデータを取得する方法をご紹介しました。このサンプルでは表示のみの機能を有効にしていますが、XamScheduleDataManager において、追加、削除、更新などを有効にし、データをサーバーへコミットさせる仕組みを実装することで、標準的なスケジュール機能を実現できます。ぜひ、試してみてください。また、筆者の Blog において今後いろいろな実装例をご紹介する予定になっていますので、こちらも併せて参照してください。

この記事は参考になりましたか?

  • このエントリーをはてなブックマークに追加
Infragistics NetAdvantageチュートリアル連載記事一覧

もっと読む

この記事の著者

インフラジスティックス・ジャパン株式会社 池原 大然(イケハラ ダイゼン)

国内ベンチャー企業にて.NETエンジニアとして開発に従事、2007年インフラジスティックス・ジャパンに入社。現在デベロッパー エバンジェリストとして、.NETやWPF/Silverlight製品や技術の啓蒙活動を行う。Microsoft MVP for Client App Dev 2010/04 ...

※プロフィールは、執筆時点、または直近の記事の寄稿時点での内容です

【AD】本記事の内容は記事掲載開始時点のものです 企画・制作 株式会社翔泳社

この記事は参考になりましたか?

この記事をシェア

  • このエントリーをはてなブックマークに追加
CodeZine(コードジン)
https://codezine.jp/article/detail/5677 2011/01/05 14:28

おすすめ

アクセスランキング

アクセスランキング

イベント

CodeZine編集部では、現場で活躍するデベロッパーをスターにするためのカンファレンス「Developers Summit」や、エンジニアの生きざまをブーストするためのイベント「Developers Boost」など、さまざまなカンファレンスを企画・運営しています。

新規会員登録無料のご案内

  • ・全ての過去記事が閲覧できます
  • ・会員限定メルマガを受信できます

メールバックナンバー

アクセスランキング

アクセスランキング