- allow net.tcp connection

pull/26/head
Simon Gockner 6 years ago
parent 1c78174389
commit ef569cf9c7
  1. 1
      GBase.Client/GBase.Client.csproj
  2. 17
      GBase.Client/Services/Service.cs

@ -28,6 +28,7 @@
<ItemGroup> <ItemGroup>
<PackageReference Include="System.ServiceModel.Http" Version="4.7.0" /> <PackageReference Include="System.ServiceModel.Http" Version="4.7.0" />
<PackageReference Include="System.ServiceModel.NetTcp" Version="4.7.0" />
</ItemGroup> </ItemGroup>
</Project> </Project>

@ -5,23 +5,30 @@
using System; using System;
using System.ServiceModel; using System.ServiceModel;
using System.Threading.Tasks; using System.Threading.Tasks;
using GBase.Api.Communication;
namespace GBase.Client.Services namespace GBase.Client.Services
{ {
public abstract class Service<TService> : IAsyncDisposable public abstract class Service<TService> : IAsyncDisposable
{ {
protected Service(string endpoint) protected Service(ServerProtocol serverProtocol, string endpoint)
{ {
ServiceFactory = OpenFactory(endpoint); ServiceFactory = OpenFactory(serverProtocol, endpoint);
} }
private ChannelFactory<TService> ServiceFactory { get; } private ChannelFactory<TService> ServiceFactory { get; }
private ChannelFactory<TService> OpenFactory(string endpoint) private ChannelFactory<TService> OpenFactory(ServerProtocol serverProtocol, string endpoint)
{ {
ChannelFactory<TService> factory = new ChannelFactory<TService>(new BasicHttpBinding(), new EndpointAddress(endpoint)); ChannelFactory<TService> factory;
factory.Open(); if (serverProtocol == ServerProtocol.Http)
factory = new ChannelFactory<TService>(new BasicHttpBinding(), new EndpointAddress(endpoint));
else if (serverProtocol == ServerProtocol.Tcp)
factory = new ChannelFactory<TService>(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; return factory;
} }

Loading…
Cancel
Save