|
|
|
@ -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; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|