# HG changeset patch # User sl # Date 1407963760 -7200 # Node ID e3d394dd0388fded1f680c379d3cb68bdfbdd61c # Parent 1a85ec2558823d82994d13fefad6f8291c5460e3 Now support duplex mode with new client. diff -r 1a85ec255882 -r e3d394dd0388 Client/Client.cs --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Client/Client.cs Wed Aug 13 23:02:40 2014 +0200 @@ -0,0 +1,60 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Forms; +using SharpDisplayManager; +using System.ServiceModel; +using System.ServiceModel.Channels; + + +namespace SharpDisplayClient +{ + public partial class ClientInput : SharpDisplayManager.IDisplayServiceCallback + { + public void OnConnected() + { + //Debug.Assert(Thread.CurrentThread.IsThreadPoolThread); + //Trace.WriteLine("Callback thread = " + Thread.CurrentThread.ManagedThreadId); + + MessageBox.Show("OnConnected()", "Client"); + } + + + public void OnServerClosing() + { + //Debug.Assert(Thread.CurrentThread.IsThreadPoolThread); + //Trace.WriteLine("Callback thread = " + Thread.CurrentThread.ManagedThreadId); + + MessageBox.Show("OnServerClosing()", "Client"); + } + } + + + + public partial class ClientOutput : DuplexClientBase, IDisplayService + { + public ClientOutput(InstanceContext callbackInstance) + : base(callbackInstance, new NetTcpBinding(), new EndpointAddress("net.tcp://localhost:8001/DisplayService")) + { } + + public void Connect(string aClientName) + { + Channel.Connect(aClientName); + } + + public void SetText(int aLineIndex, string aText) + { + Channel.SetText(aLineIndex, aText); + } + + + public void SetTexts(System.Collections.Generic.IList aTexts) + { + Channel.SetTexts(aTexts); + } + + + } +} diff -r 1a85ec255882 -r e3d394dd0388 Client/MainForm.cs --- a/Client/MainForm.cs Tue Aug 12 21:27:35 2014 +0200 +++ b/Client/MainForm.cs Wed Aug 13 23:02:40 2014 +0200 @@ -9,14 +9,14 @@ using System.Windows.Forms; using System.ServiceModel; using System.ServiceModel.Channels; -using SharpDisplayManager; + namespace SharpDisplayClient { public partial class MainForm : Form { - ChannelFactory iChannelFactory; - SharpDisplayManager.IDisplayService iClient; + ClientOutput iClientOutput; + ClientInput iClientInput; public MainForm() { @@ -27,18 +27,17 @@ { //iClient.SetText(0,"Top"); //iClient.SetText(1, "Bottom"); - iClient.SetTexts(new string[] { "Top", "Bottom" }); + iClientOutput.SetTexts(new string[] { "Top", "Bottom" }); } private void MainForm_Load(object sender, EventArgs e) { + iClientInput = new ClientInput(); + InstanceContext context = new InstanceContext(iClientInput); + iClientOutput = new ClientOutput(context); - iChannelFactory = new ChannelFactory( - new NetNamedPipeBinding(), - new EndpointAddress( - "net.pipe://localhost/DisplayService")); + iClientOutput.Connect("TestClient"); - iClient = iChannelFactory.CreateChannel(); } } } diff -r 1a85ec255882 -r e3d394dd0388 Client/SharpDisplayClient.csproj --- a/Client/SharpDisplayClient.csproj Tue Aug 12 21:27:35 2014 +0200 +++ b/Client/SharpDisplayClient.csproj Wed Aug 13 23:02:40 2014 +0200 @@ -45,6 +45,7 @@ + Form diff -r 1a85ec255882 -r e3d394dd0388 Server/MainForm.cs --- a/Server/MainForm.cs Tue Aug 12 21:27:35 2014 +0200 +++ b/Server/MainForm.cs Wed Aug 13 23:02:40 2014 +0200 @@ -350,10 +350,10 @@ iServiceHost = new ServiceHost ( typeof(DisplayServer), - new Uri[] { new Uri("net.pipe://localhost") } + new Uri[] { new Uri("net.tcp://localhost:8001/") } ); - iServiceHost.AddServiceEndpoint(typeof(IDisplayService), new NetNamedPipeBinding(), "DisplayService"); + iServiceHost.AddServiceEndpoint(typeof(IDisplayService), new NetTcpBinding(), "DisplayService"); iServiceHost.Open(); } diff -r 1a85ec255882 -r e3d394dd0388 Server/Servers.cs --- a/Server/Servers.cs Tue Aug 12 21:27:35 2014 +0200 +++ b/Server/Servers.cs Wed Aug 13 23:02:40 2014 +0200 @@ -1,6 +1,7 @@ using System; using System.Windows.Forms; using System.Collections; +using System.ServiceModel; namespace SharpDisplayManager { @@ -8,6 +9,7 @@ /// Implement our display service. /// This class is instantiated anew whenever a client send a request. /// + [ServiceBehavior(ConcurrencyMode = ConcurrencyMode.Reentrant)] class DisplayServer : IDisplayService { //From IDisplayService @@ -41,6 +43,13 @@ } } + // + public void Connect(string aClientName) + { + IDisplayServiceCallback callback = OperationContext.Current.GetCallbackChannel(); + callback.OnConnected(); + } + } } diff -r 1a85ec255882 -r e3d394dd0388 Server/Services.cs --- a/Server/Services.cs Tue Aug 12 21:27:35 2014 +0200 +++ b/Server/Services.cs Wed Aug 13 23:02:40 2014 +0200 @@ -2,15 +2,29 @@ using System.ServiceModel; using System.Collections; + namespace SharpDisplayManager { - [ServiceContract] + [ServiceContract(CallbackContract = typeof(IDisplayServiceCallback))] public interface IDisplayService { - [OperationContract] + [OperationContract(IsOneWay = true)] + void Connect(string aClientName); + + [OperationContract(IsOneWay = true)] void SetText(int aLineIndex, string aText); - [OperationContract] + [OperationContract(IsOneWay = true)] void SetTexts(System.Collections.Generic.IList aTexts); } + + + public interface IDisplayServiceCallback + { + [OperationContract(IsOneWay = true)] + void OnConnected(); + + [OperationContract] + void OnServerClosing(); + } }