WCF サービスの実装
xamSchedule にはクライアントにスケジュール データを提供するための WCF サービスクラスを 2 個用意しています。用途に合わせて選択してください。
| クラス | 概要 |
| WcfListConnectorServiceSingle | 1 度のみ作成されるサービスインスタンス。クライアントからのリモート コールはサーバーの同じスレッドで動作するためパフォーマンスの低下を防げる。ただし、接続クライアント数が多い場合はボトルネックが発生し、それがパフォーマンス低下につながる可能性がある |
| WcfListConnectorServiceMulti | 抽象クラス。クライアントからのリモート コールごとに新しいインスタンスが作成され、サーバーの異なるスレッドで動作する。クライアント接続数が多い場合にボトルネックを発生しにくい。ただし、毎回インスタンスを作成するので、クライアント数が多くない場合にはパフォーマンスは Single に比べ低くなる |
この記事では WcfListConnectorServiceSingle を利用します。そのため、xamSchedule_SL.Web プロジェクトに次のアセンブリ参照を追加します。
- Infragistics4.Services.Schedules.WcfConnectorService.v10.3.dll
次に、[新しい項目の追加] - [Silverlight] を選択し、Silverlight 対応 WCF サービス を "XamScheduleWCFService" と名付け作成します。
作成された XamScheduleWCFService.svc.cs を開き、WcfListConnectorServiceSingle を継承します。また、ASP.NET 互換となるように設定します。このクラスではエンティティのマッピングを行っています。
using System.ServiceModel.Activation;
using Infragistics.Services.Schedules;
using Infragistics.Controls.Schedules.Services;
namespace xamSchedule_SL.Web
{
// ASP.NET 互換を設定
[AspNetCompatibilityRequirements(RequirementsMode=AspNetCompatibilityRequirementsMode.Allowed)]
public class XamScheduleWCFService : WcfListConnectorServiceSingle
{
// スケジュール エンティティ
private xamSchedule_SampleEntities entities;
public XamScheduleWCFService()
{
entities = new xamSchedule_SampleEntities();
// リソースの設定
this.ResourceItemsSource = entities.Resources;
this.ResourcePropertyMappings =
new ResourcePropertyMappingCollection();
this.ResourcePropertyMappings.UseDefaultMappings = true;
// リソースカレンダーの設定
this.ResourceCalendarItemsSource = entities.ResourceCalendars;
this.ResourceCalendarPropertyMappings =
new ResourceCalendarPropertyMappingCollection();
this.ResourceCalendarPropertyMappings.UseDefaultMappings = true;
// 予定の設定
this.AppointmentItemsSource = entities.Appointments;
this.AppointmentPropertyMappings =
new AppointmentPropertyMappingCollection();
this.AppointmentPropertyMappings.UseDefaultMappings = true;
}
}
}
サービスの実装を完了し、Web.Config の contract を修正します。
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<system.web>
<compilation debug="true" targetFramework="4.0">
<assemblies>
<add assembly="System.Data.Entity, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
</assemblies>
</compilation>
</system.web>
<connectionStrings>
<add name="xamSchedule_SampleEntities" connectionString="metadata=res://*/XamScheduleDataModel.csdl|res://*/XamScheduleDataModel.ssdl|res://*/XamScheduleDataModel.msl;provider=System.Data.SqlClient;provider connection string="Data Source=.\SQLEXPRESS;Initial Catalog=xamSchedule_Sample;Integrated Security=True;MultipleActiveResultSets=True"" providerName="System.Data.EntityClient" />
</connectionStrings>
<system.serviceModel>
<behaviors>
<serviceBehaviors>
<behavior name="">
<serviceMetadata httpGetEnabled="true" />
<serviceDebug includeExceptionDetailInFaults="false" />
</behavior>
</serviceBehaviors>
</behaviors>
<bindings>
<customBinding>
<binding name="xamSchedule_SL.Web.XamScheduleWCFService.customBinding0">
<binaryMessageEncoding />
<httpTransport />
</binding>
</customBinding>
</bindings>
<services>
<!-- コントラクトを Infragistics.Services.Schedules.IWcfListConnectorService に修正-->
<service name="xamSchedule_SL.Web.XamScheduleWCFService">
<endpoint address="" binding="customBinding" bindingConfiguration="xamSchedule_SL.Web.XamScheduleWCFService.customBinding0"
contract="Infragistics.Services.Schedules.IWcfListConnectorService" />
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
</service>
</services>
<serviceHostingEnvironment aspNetCompatibilityEnabled="true"
multipleSiteBindingsEnabled="true" />
</system.serviceModel>
</configuration>
XamScheduleWCFService.svc をブラウザで開き、下記のような画面が出力されることを確認します。




