From ef569cf9c73f3adf87a3afa7cc3572d8cbc94150 Mon Sep 17 00:00:00 2001 From: Simon Gockner Date: Tue, 11 Feb 2020 16:22:41 +0100 Subject: [PATCH] - allow net.tcp connection --- GBase.Client/GBase.Client.csproj | 1 + GBase.Client/Services/Service.cs | 17 ++++++++++++----- 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/GBase.Client/GBase.Client.csproj b/GBase.Client/GBase.Client.csproj index 30fe1b7..fe4029e 100644 --- a/GBase.Client/GBase.Client.csproj +++ b/GBase.Client/GBase.Client.csproj @@ -28,6 +28,7 @@ + diff --git a/GBase.Client/Services/Service.cs b/GBase.Client/Services/Service.cs index a58b949..a4cf456 100644 --- a/GBase.Client/Services/Service.cs +++ b/GBase.Client/Services/Service.cs @@ -5,23 +5,30 @@ using System; using System.ServiceModel; using System.Threading.Tasks; +using GBase.Api.Communication; namespace GBase.Client.Services { public abstract class Service : IAsyncDisposable { - protected Service(string endpoint) + protected Service(ServerProtocol serverProtocol, string endpoint) { - ServiceFactory = OpenFactory(endpoint); + ServiceFactory = OpenFactory(serverProtocol, endpoint); } private ChannelFactory ServiceFactory { get; } - private ChannelFactory OpenFactory(string endpoint) + private ChannelFactory OpenFactory(ServerProtocol serverProtocol, string endpoint) { - ChannelFactory factory = new ChannelFactory(new BasicHttpBinding(), new EndpointAddress(endpoint)); - factory.Open(); + ChannelFactory factory; + if (serverProtocol == ServerProtocol.Http) + factory = new ChannelFactory(new BasicHttpBinding(), new EndpointAddress(endpoint)); + else if (serverProtocol == ServerProtocol.Tcp) + factory = new ChannelFactory(new NetTcpBinding(), new EndpointAddress(endpoint)); //TODO: Set security mode here? + else + throw new ArgumentOutOfRangeException(nameof(serverProtocol), serverProtocol, "Invalid server protocol used."); + factory.Open(); return factory; }