Last change
on this file since 13905 was
13887,
checked in by thasling, 8 years ago
|
prepared protoype for next meeting
|
File size:
1.2 KB
|
Line | |
---|
1 | using System;
|
---|
2 | using System.ServiceModel;
|
---|
3 | using DistributedGA.Core.Domain;
|
---|
4 | using DistributedGA.Core.Interface;
|
---|
5 |
|
---|
6 | namespace DistributedGA.Core.Implementation
|
---|
7 | {
|
---|
8 | public class WcfMessageSender : IMessageSender
|
---|
9 | {
|
---|
10 | private PeerInfo myself;
|
---|
11 |
|
---|
12 | public void Init(PeerInfo source)
|
---|
13 | {
|
---|
14 | myself = source;
|
---|
15 | }
|
---|
16 |
|
---|
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 | }
|
---|
37 |
|
---|
38 | }
|
---|
39 | }
|
---|
Note: See
TracBrowser
for help on using the repository browser.