1: public class YourDuplexServiceFactory : ServiceHostFactoryBase
2: {
3: public override ServiceHostBase CreateServiceHost(string constructorString,
4: Uri[] baseAddresses)
5: {
6: return new PollingDuplexSimplexServiceHost(baseAddresses);
7: }
8: }
9:
10: internal class PollingDuplexSimplexServiceHost : ServiceHost
11: {
12: public PollingDuplexSimplexServiceHost(params Uri[] addresses)
13: {
14: InitializeDescription(typeof(YourDuplexService), new UriSchemeKeyedCollection(addresses));
15: Description.Behaviors.Add(new ServiceMetadataBehavior());
16:
17: var throttle = Description.Behaviors.Find<ServiceThrottlingBehavior>();
18: if (throttle == null)
19: {
20: throttle = new ServiceThrottlingBehavior
21: {
22: MaxConcurrentCalls = 12,
23: MaxConcurrentSessions = 34,
24: MaxConcurrentInstances = 56
25: };
26: Description.Behaviors.Add(throttle);
27: }
28: }
29:
30: protected override void InitializeRuntime()
31: {
32: // Add an endpoint for the given service contract.
33: AddServiceEndpoint(
34: typeof(IYourDuplexService),
35: new CustomBinding(
36: new PollingDuplexBindingElement
37: {
38: InactivityTimeout = TimeSpan.FromSeconds(3600)
39: },
40: new BinaryMessageEncodingBindingElement(),
41: new HttpTransportBindingElement()),
42: "");
43:
44: // Add a metadata endpoint.
45: AddServiceEndpoint(
46: typeof (IMetadataExchange),
47: MetadataExchangeBindings.CreateMexHttpBinding(),
48: "mex");
49:
50: base.InitializeRuntime();
51: }
52: }