Free cookie consent management tool by TermsFeed Policy Generator

source: branches/thasling/DistributedGA/DistributedGA.Core/Implementation/WcfMessageSender.cs @ 13557

Last change on this file since 13557 was 13557, checked in by thasling, 8 years ago

Implemented P2PTask-class
Changed communication protocoll http --> net.tcp
Logger is now Parameter of P2PTask

File size: 1.1 KB
Line 
1using System;
2using System.ServiceModel;
3using DistributedGA.Core.Domain;
4using DistributedGA.Core.Interface;
5
6namespace DistributedGA.Core.Implementation {
7  public class WcfMessageSender : IMessageSender {
8    private PeerInfo myself;
9
10    public void Init(PeerInfo source) {
11      myself = source;
12    }
13
14    public void SendData(PeerInfo destination, SolutionInfo[] data) {
15      var client = CreateServerClient(destination.IpAddress, destination.Port);
16      client.SendData(myself, data); //maybe timout exception...
17    }
18
19    private IMessageContract CreateServerClient(string ip, int port) {
20      var serviceUrl = "DistributedGA.svc";
21      var baseUri = new Uri(string.Concat("net.tcp://", ip, ":", port, "/DistributedGA"));
22      var serviceUri = new Uri(baseUri, serviceUrl);
23
24      var binding = new NetTcpBinding();
25      var endpoint = new EndpointAddress(serviceUri);
26      var myChannelFactory = new ChannelFactory<IMessageContract>(binding, endpoint);
27
28      IMessageContract client = null;
29      client = myChannelFactory.CreateChannel();
30      return client;
31    }
32
33  }
34}
Note: See TracBrowser for help on using the repository browser.