2 // Copyright (c) Microsoft Corporation. All Rights Reserved.
6 using System
.ServiceModel
.Channels
;
7 using System
.ServiceModel
;
8 using System
.Configuration
;
9 using System
.Collections
;
11 namespace Microsoft
.ServiceModel
.Samples
13 // Create a service contract and define the service operations.
15 public interface ISampleContract
17 [OperationContract(IsOneWay
= true)]
18 void ReportWindSpeed(int speed
);
21 // The Service implementation implements your service contract.
22 public class SampleService
: ISampleContract
24 public void ReportWindSpeed(int speed
)
28 Console
.WriteLine("Dangerous wind detected! Reported speed (" + speed
+ ") is greater than 64 kph.");
33 class DroppingServerElement
: InterceptingElement
35 protected override ChannelMessageInterceptor
CreateMessageInterceptor()
37 return new DroppingServerInterceptor();
41 public class DroppingServerInterceptor
: ChannelMessageInterceptor
43 int messagesSinceLastReport
= 0;
44 readonly int reportPeriod
= 5;
46 public DroppingServerInterceptor() { }
48 public override void OnReceive(ref Message msg
)
50 if (msg
.Headers
.FindHeader("ByPass", "urn:InterceptorNamespace") > 0)
52 if (++messagesSinceLastReport
== this.reportPeriod
)
54 Console
.WriteLine(reportPeriod
+ " wind speed reports have been received.");
58 // Drop incoming Message if the Message does not have the special header
62 public override ChannelMessageInterceptor
Clone()
64 return new DroppingServerInterceptor();
70 static void Main(string[] args
)
72 ServiceHost serviceHost
= new ServiceHost(typeof(SampleService
));
79 System
.Console
.WriteLine("Press ENTER to exit.");
80 System
.Console
.ReadLine();