私が取り組んでいるプロジェクトで CustomHost を定義した方法は次のとおりです。
<%@ ServiceHost Language="C#" Debug="true" Service="Servicename.Servicename" CodeBehind="Service1.svc.cs" Factory="WcfService1.CustomServiceHostFactory"%>
この、
public class CustomServiceHostFactory : ServiceHostFactory
{
public CustomServiceHostFactory()
{
}
protected override ServiceHost CreateServiceHost(Type serviceType, Uri[] baseAddresses)
{
return new CustomServiceHost(serviceType, baseAddresses);
}
}
public class CustomServiceHost : ServiceHost
{
public CustomServiceHost()
{
}
public CustomServiceHost(Type serviceType, params Uri[] baseAddresses)
: base(serviceType, baseAddresses)
{
}
protected override void OnOpening()
{
base.OnOpening();
}
protected override void OnClosing()
{
base.OnClosing();
}
protected override void ApplyConfiguration()
{
base.ApplyConfiguration();
}
}
CustomServiceHost がむき出しのように見えることに注意してください。これは、私のソリューションでは、この CustomServiceHost に多くのログと構成があり、削除して適切ではないためです。
私が見ることができる他の違いは、CustomServiceHost がエンドポイントを追加しないことです。エンドポイントは、次のように構成ファイルで定義されます。
<system.serviceModel>
<behaviors>
<serviceBehaviors>
<behavior name="ServiceBehavior">
<serviceMetadata httpGetEnabled="true" />
<serviceDebug includeExceptionDetailInFaults="false" />
</behavior>
</serviceBehaviors>
</behaviors>
<services>
<service name="Servicename.Servicename" behaviorConfiguration="ServiceBehavior">
<endpoint address="http://*******.svc" binding="wsHttpBinding" contract="Namespace.IContract" bindingConfiguration="BindingConfig">
</endpoint>
</service>
</services>
<bindings>
<wsHttpBinding>
<binding name="BindingConfig" maxReceivedMessageSize="9291456">
<security mode="None">
</security>
<readerQuotas maxArrayLength="6291456" />
</binding>
</wsHttpBinding>
</bindings>