Skip to content

Instantly share code, notes, and snippets.

@masaru-b-cl
Created November 21, 2012 03:11
Show Gist options
  • Save masaru-b-cl/4122779 to your computer and use it in GitHub Desktop.
Save masaru-b-cl/4122779 to your computer and use it in GitHub Desktop.
共通のバインディング設定を使ったエンドポイント追加用Factory
using System.ServiceModel;
using System.ServiceModel.Activation;
namespace TAKANO_Sho.Wcf.Extensions
{
/// <summary>
/// 共通設定を行うWCFサービスホストを作成します。
/// </summary>
/// <typeparam name="TService">サービス型。</typeparam>
/// <typeparam name="TServiceContract">サービスコントラクト型。</typeparam>
public class ServiceHostFactoryBase<TService, TServiceContract> : ServiceHostFactory
{
/// <summary>
/// 指定したベース アドレスを持ち、指定したデータでそれを初期化する System.ServiceModel.ServiceHost を作成します。
/// </summary>
/// <param name="constructorString">ファクトリによって構築された System.ServiceModel.ServiceHostBase インスタンスに渡される初期化データ。</param>
/// <param name="baseAddresses">ホストされるサービスのベース アドレスを格納する System.Uri 型の System.Array。</param>
/// <returns>指定したベース アドレスを持つ System.ServiceModel.ServiceHost。</returns>
public override ServiceHostBase CreateServiceHost(string constructorString, System.Uri[] baseAddresses)
{
var host = new ServiceHost(typeof(TService), baseAddresses);
host.AddServiceEndpoint(typeof(TServiceContract),
new BasicHttpBinding
{
MaxReceivedMessageSize = 655360,
MaxBufferSize = 655360,
MaxBufferPoolSize = 5242880
},
"");
return host;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment