I have a custom behavior for a service where I want to specify a receive timeout value, I have created a behavior and on the build service header.
I use the declarative attribute to apply the behavior or as I thought. But the behavior seems to make no difference, i.e. the set timeout value is not being applied as expected.
However when I have noticed the behavior is only being applied when the host is opened rather than when created.
The same behavior when applied explicitly through does work.
Any ideas?
Behavior:
[AttributeUsage(AttributeTargets.Class)]
public class BuildServiceBindingBehavior : Attribute, IServiceBehavior
{
public BuildServiceBindingBehavior( string p_receiveTime )
{
ReceiveTimeout = TimeSpan.Parse( p_receiveTime );
}
#region IServiceBehavior Members
public void AddBindingParameters( ServiceDescription serviceDescription, ServiceHostBase serviceHostBase, System.Collections.ObjectModel.Collection<ServiceEndpoint> endpoints, System.ServiceModel.Channels.BindingParameterCollection bindingParameters )
{
}
public void ApplyDispatchBehavior( ServiceDescription serviceDescription, ServiceHostBase serviceHostBase )
{
// add this behavior to each endpoint
foreach ( var endPoint in serviceDescription.Endpoints )
{
endPoint.Binding.ReceiveTimeout = ReceiveTimeout;
}
}
public void Validate( ServiceDescription serviceDescription, ServiceHostBase serviceHostBase )
{
}
#endregion
internal TimeSpan ReceiveTimeout { get; set; }
}
Service code:
[ServiceBehavior(Name = "DotNetBuildsService",
InstanceContextMode = InstanceContextMode.PerSession,
ConcurrencyMode = ConcurrencyMode.Single
)]
// Set receieve time out
[BuildServiceBindingBehavior( "0:0:1" )]
public class BuildService : IBuildTasksService
{
//implementation code
}