Changeset 13918 for branches/thasling/DistributedGA/DistributedGA.Core/Implementation/WcfMessageSender.cs
- Timestamp:
- 06/17/16 17:46:40 (8 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/thasling/DistributedGA/DistributedGA.Core/Implementation/WcfMessageSender.cs
r13887 r13918 4 4 using DistributedGA.Core.Interface; 5 5 6 namespace DistributedGA.Core.Implementation 7 { 8 public class WcfMessageSender : IMessageSender 9 { 10 private PeerInfo myself; 6 namespace DistributedGA.Core.Implementation { 7 public class WcfMessageSender : IMessageSender { 8 private PeerInfo myself; 11 9 12 public void Init(PeerInfo source) 13 { 14 myself = source; 10 public void Init(PeerInfo source) { 11 myself = source; 12 } 13 14 public void SendData(PeerInfo destination, byte[][] data) { 15 16 var serviceUrl = "DistributedGA.svc"; 17 var baseUri = new Uri(string.Concat("net.tcp://", destination.IpAddress, ":", destination.Port, "/DistributedGA")); 18 var serviceUri = new Uri(baseUri, serviceUrl); 19 20 var binding = new NetTcpBinding(); 21 var endpoint = new EndpointAddress(serviceUri); 22 using (var myChannelFactory = new ChannelFactory<IMessageContract>(binding, endpoint)) { 23 using (IClientChannel client = (IClientChannel)myChannelFactory.CreateChannel()) { 24 ((IMessageContract)client).SendData(myself, data); //maybe timout exception... 15 25 } 26 } 27 } 16 28 17 public void SendData(PeerInfo destination, byte[][] data) 18 { 19 var client = CreateServerClient(destination.IpAddress, destination.Port); 20 client.SendData(myself, data); //maybe timout exception... 21 } 22 23 private IMessageContract CreateServerClient(string ip, int port) 24 { 25 var serviceUrl = "DistributedGA.svc"; 26 var baseUri = new Uri(string.Concat("net.tcp://", ip, ":", port, "/DistributedGA")); 27 var serviceUri = new Uri(baseUri, serviceUrl); 28 29 var binding = new NetTcpBinding(); 30 var endpoint = new EndpointAddress(serviceUri); 31 var myChannelFactory = new ChannelFactory<IMessageContract>(binding, endpoint); 32 33 IMessageContract client = null; 34 client = myChannelFactory.CreateChannel(); 35 return client; 36 } 29 public void Dispose() { 37 30 38 31 } 32 } 39 33 }
Note: See TracChangeset
for help on using the changeset viewer.