Free cookie consent management tool by TermsFeed Policy Generator

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

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

Upload des Projekts letztendlich, trotz buggendes Clients...

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