Project Description
Project combines mine extensions to .NET Core, WCF, ADO.NET SQL Server Provider, SQL Server Profiler, WinForms, etc

How to WCF Behaviors?

How do I share client context (e.g. static data) on the server:
A: [Test] Test_Transparent_Delivery_Behavior() at TestAll.cs
[Test]
public void Test_Transparent_Delivery_Behavior()
{
    int arrivedId = 0;
    string arrivedCulture = null;

    var tdc = new TransparentDeliveryConfiguration(
        delegate(string action, DeliveryDictionary data)
        {
            data.Set<int>("ID", 321);
            data.Set<string>("Culture", "en-US");
        },
        delegate(string action, DeliveryDictionary data)
        {
            arrivedId = data.Get<int>("ID");
            arrivedCulture = data.Get<string>("Culture");
        });

    ServiceHost host = MyEnvionment.CreateService<IService1<int>, Service1<int>>();
    // DISPATCHER CONFIGURATION
    host.Description.Behaviors.Add(new TransparentDeliveryBehavior(tdc));
    host.Open();

    ChannelFactory<IService1<int>> channel = MyEnvionment.CreateProxy<IService1<int>>();
    // CLIENT CHANNEL CONFIGURATION
    channel.Endpoint.Behaviors.Add(new TransparentDeliveryBehavior(tdc));
    var service1 = channel.CreateChannel(MyEnvionment.GetEndPointUri<IService1<int>>());

    service1.GetData(
        new CompositeType() { BoolValue = true, StringValue = "Hello" }
        );

    channel.Close();
    host.Close();

    Assert.AreEqual(321, arrivedId);
    Assert.AreEqual("en-US", arrivedCulture);
}

How to catch traffic structure of a WCF communication:
A: [Test] Test_Traffic_Behavior() at TestAll.cs
[Test]
public void Test_Traffic_Behavior()
{
    TrafficStatistic serverTraffic = new TrafficStatistic();
    var serverConfiguration = new TrafficStatisticConfiguration(
        delegate { },
        serverTraffic.Merge);

    ServiceHost host = MyEnvionment.CreateService<IService1<int>, Service1<int>>();
    // DISPATCHER's CONFIGURATION
    host.Description.Behaviors.Add(new TrafficBehavior(serverConfiguration));
    host.Open();

    TrafficStatistic clientTraffic = new TrafficStatistic();
    var clientConfiguration = new TrafficStatisticConfiguration(
        clientTraffic.Merge,
        delegate { });

    ChannelFactory<IService1<int>> channel = MyEnvionment.CreateProxy<IService1<int>>();
    channel.Endpoint.Behaviors.Add(new TrafficBehavior(clientConfiguration));
    var service1 = channel.CreateChannel(MyEnvionment.GetEndPointUri<IService1<int>>());

    service1.GetData(
        new CompositeType() {BoolValue = true, StringValue = "Hello"}
        );

    channel.Close();
    host.Close();

    Assert.Greater(serverTraffic.Total.Recieved, 0);
    Assert.Greater(serverTraffic.Total.Sent, 0);
    Assert.AreEqual(1, serverTraffic.Total.Requests);

    Assert.Greater(clientTraffic.Total.Recieved, 0);
    Assert.Greater(clientTraffic.Total.Sent, 0);
    Assert.AreEqual(1, clientTraffic.Total.Requests);
}
Also this behavior is supported by out of the box solution: TrafficProfiler
Traffic Profiler Sample

How does TrafficProfiler works?
A: TrafficProfiler expects traffic structure of an app on net.pipe://localhost/Universe.TrafficProfiler/Info/{process-id} end-point. That publication is implemented by TrafficPublisher.Publish() method

See also another projects:
What does MediaProbe support?

Last edited Aug 27, 2014 at 5:41 PM by Devizer, version 11