Silverlight アプリケーション ソリューションでサービスを使用
xamSchedule_SL プロジェクトでサービスを使用する場合、参照設定から [サービス参照の追加] を選択します。先ほど作成したサービスが表示されますので、サービスの名前空間を "XamScheduleWCFService" とし、追加します。
プロジェクトに ServiceReferences.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で設定したコードによる予定追加部分を削除します。
using System.Windows.Controls;
namespace xamSchedule_SL
{
public partial class MainPage : UserControl
{
public MainPage()
{
InitializeComponent();
}
}
}
MainPage.xaml に追加されているコントロールをすべて削除し、新たに XamMonthView, XamScheduleDataManager, WcfListDataConnector を追加します。
<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 を連結します。
<ig:XamMonthView Name="xamMonthView1"
DataManager="{Binding ElementName=xamScheduleDataManager1}"/>
XamScheduleDataManager と WcfListScheduleDataConnector を連結します。また、今回はリソース ID をあらかじめ定義しておきます。
<ig:XamScheduleDataManager Name="xamScheduleDataManager1"
DataConnector="{Binding ElementName=wcfListScheduleDataConnector1}"
CurrentUserId="R0001" />
最後に WcfListScheduleDataConnector にエンドポイント設定名やデータ取得間隔を指定します。
<ig:WcfListScheduleDataConnector Name="wcfListScheduleDataConnector1" EndpointConfigurationName="CustomBinding_IWcfListConnectorService" PollingInterval="00:00:30" PollingMode="Detailed" />
すべてが正しく設定されていると、実行時にDB からスケジュールデータを取得し、表示することが可能になります。
まとめ
今回は WCF サービスを構築し、データ ベースからスケジュールデータを取得する方法をご紹介しました。このサンプルでは表示のみの機能を有効にしていますが、XamScheduleDataManager において、追加、削除、更新などを有効にし、データをサーバーへコミットさせる仕組みを実装することで、標準的なスケジュール機能を実現できます。ぜひ、試してみてください。また、筆者の Blog において今後いろいろな実装例をご紹介する予定になっていますので、こちらも併せて参照してください。



