init
This commit is contained in:
commit
e124a47765
19374 changed files with 9806149 additions and 0 deletions
55
Kreta.Client/ClientHelper.cs
Normal file
55
Kreta.Client/ClientHelper.cs
Normal file
|
@ -0,0 +1,55 @@
|
|||
using System;
|
||||
using System.ServiceModel;
|
||||
using Kreta.Resources;
|
||||
|
||||
namespace Kreta.Client
|
||||
{
|
||||
public class ClientHelper
|
||||
{
|
||||
//TODO:Exceptionokat szétszedni
|
||||
public T CallService<TService, T>(Func<TService, T> action) where TService : ICommunicationObject, new()
|
||||
{
|
||||
T res;
|
||||
var client = default(TService);
|
||||
|
||||
try
|
||||
{
|
||||
client = new TService();
|
||||
|
||||
res = action(client);
|
||||
client.Close();
|
||||
}
|
||||
catch (TimeoutException ex)
|
||||
{
|
||||
throw new TimeoutException(ErrorResource.AzAdatokLekerdezesereTullepteAMegadottIdokeretet, ex);
|
||||
}
|
||||
catch (FaultException ex)
|
||||
{
|
||||
throw new Exception(ErrorResource.AKirBejelentkezesiAdatokNemMegfeleloekKerjukProbaljaMegismetelniABejelentkezest, ex);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
throw new Exception(ex.Message, ex);
|
||||
}
|
||||
finally
|
||||
{
|
||||
CloseClientCommunication(client);
|
||||
}
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
private void CloseClientCommunication<TService>(TService client) where TService : ICommunicationObject, new()
|
||||
{
|
||||
if (client.State == CommunicationState.Faulted)
|
||||
{
|
||||
client.Abort();
|
||||
|
||||
}
|
||||
else if (client.State != CommunicationState.Closed)
|
||||
{
|
||||
client.Close();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue