Files
BeWoPlaner/BeWo/ServiceProxy/ServiceConfig.cs
2021-09-30 15:31:13 +02:00

169 lines
6.6 KiB
C#

using System;
using System.Collections.Generic;
using System.Linq;
using System.ServiceModel;
using System.ServiceModel.Description;
using System.Text;
using System.Threading.Tasks;
namespace BeWo.ServiceProxy
{
public static class ServiceConfig
{
public static BasicHttpBinding BeWoBasicHttpBinding = new BasicHttpBinding()
{
Name = "BeWoBasicEndpoint",
CloseTimeout = new TimeSpan(0, 5, 0),
OpenTimeout = new TimeSpan(0, 5, 0),
ReceiveTimeout = new TimeSpan(0, 10, 0),
SendTimeout = new TimeSpan(0, 5, 0),
AllowCookies = false,
BypassProxyOnLocal = false,
HostNameComparisonMode = HostNameComparisonMode.StrongWildcard,
MaxBufferPoolSize = 524288,
MaxBufferSize = int.MaxValue,
MaxReceivedMessageSize = int.MaxValue,
TextEncoding = Encoding.UTF8,
TransferMode = TransferMode.Buffered,
UseDefaultWebProxy = true,
MessageEncoding = WSMessageEncoding.Text,
ReaderQuotas = new System.Xml.XmlDictionaryReaderQuotas
{
MaxDepth = 32,
MaxStringContentLength = int.MaxValue,
MaxArrayLength = int.MaxValue,
MaxBytesPerRead = 4096,
MaxNameTableCharCount = 16384
},
Security = new BasicHttpSecurity
{
Mode = BasicHttpSecurityMode.None
}
};
public static BasicHttpBinding BeWoStreamingBinding = new BasicHttpBinding()
{
Name = "BeWoStreamingEndpoint",
ReceiveTimeout = new TimeSpan(10, 0, 0),
SendTimeout = new TimeSpan(10, 0, 0),
MaxBufferSize = 65536,
MaxReceivedMessageSize = 67108864,
TextEncoding = Encoding.UTF8,
TransferMode = TransferMode.StreamedRequest,
UseDefaultWebProxy = true,
MessageEncoding = WSMessageEncoding.Text,
ReaderQuotas = new System.Xml.XmlDictionaryReaderQuotas
{
MaxDepth = 32,
MaxStringContentLength = 8192,
MaxArrayLength = 16384,
MaxBytesPerRead = 4096,
MaxNameTableCharCount = 16384
},
Security = new BasicHttpSecurity
{
Mode = BasicHttpSecurityMode.None
}
};
public static BasicHttpBinding QueryServiceBinding = new BasicHttpBinding()
{
Name = "BeWoBasicEndpoint",
CloseTimeout = new TimeSpan(0, 5, 0),
OpenTimeout = new TimeSpan(0, 5, 0),
ReceiveTimeout = new TimeSpan(0, 10, 0),
SendTimeout = new TimeSpan(0, 5, 0),
AllowCookies = false,
BypassProxyOnLocal = false,
HostNameComparisonMode = HostNameComparisonMode.StrongWildcard,
MaxBufferPoolSize = 524288,
MaxBufferSize = int.MaxValue,
MaxReceivedMessageSize = int.MaxValue,
TextEncoding = Encoding.UTF8,
TransferMode = TransferMode.Buffered,
UseDefaultWebProxy = true,
MessageEncoding = WSMessageEncoding.Text,
ReaderQuotas = new System.Xml.XmlDictionaryReaderQuotas
{
MaxDepth = 32,
MaxStringContentLength = 8192,
MaxArrayLength = 16384,
MaxBytesPerRead = 4096,
MaxNameTableCharCount = 16384
},
Security = new BasicHttpSecurity
{
Mode = BasicHttpSecurityMode.None
}
};
public static Dictionary<Type, BasicHttpBinding> HttpBindingConfiguration = new Dictionary<Type, BasicHttpBinding>
{
{ typeof(IQueryService), QueryServiceBinding},
{ typeof(IStreamingService), BeWoStreamingBinding},
{ typeof(IEmployeeService), BeWoBasicHttpBinding },
{ typeof(ICustomerService), BeWoBasicHttpBinding },
{ typeof(IUserService), BeWoBasicHttpBinding },
{ typeof(IValueListService), BeWoBasicHttpBinding },
{ typeof(IDownloadService), BeWoBasicHttpBinding },
{ typeof(IResourceService), BeWoBasicHttpBinding },
{ typeof(IOperationsService), BeWoBasicHttpBinding },
{ typeof(IAnalysisService), BeWoBasicHttpBinding },
{ typeof(IMailService), BeWoBasicHttpBinding },
{ typeof(IAccountingService), BeWoBasicHttpBinding},
{ typeof(IReportService), BeWoBasicHttpBinding}
};
public static Dictionary<Type, BasicHttpBinding> ServiceClient = new Dictionary<Type, BasicHttpBinding>
{
{ typeof(IQueryService), QueryServiceBinding},
{ typeof(IStreamingService), BeWoStreamingBinding},
{ typeof(IEmployeeService), BeWoBasicHttpBinding },
{ typeof(ICustomerService), BeWoBasicHttpBinding },
{ typeof(IUserService), BeWoBasicHttpBinding },
{ typeof(IValueListService), BeWoBasicHttpBinding },
{ typeof(IDownloadService), BeWoBasicHttpBinding },
{ typeof(IResourceService), BeWoBasicHttpBinding },
{ typeof(IOperationsService), BeWoBasicHttpBinding },
{ typeof(IAnalysisService), BeWoBasicHttpBinding },
{ typeof(IMailService), BeWoBasicHttpBinding },
{ typeof(IAccountingService), BeWoBasicHttpBinding},
{ typeof(IReportService), BeWoBasicHttpBinding}
};
public static TClient GetClient<TClient, TInterface>()
where TClient : ClientBase<TInterface>, TInterface, new()
where TInterface : class
{
TClient client = null;
try
{
client = new TClient();
}
catch (Exception e)
{
}
var binding = HttpBindingConfiguration[typeof(TInterface)];
var endpoint = ServiceFacade.EndpointAddresses[typeof(TInterface)];
client = //new UserServiceClient(binding, endpoint) as TClient;
(TClient)Activator.CreateInstance(typeof(TClient), new object[] {binding, endpoint});
if (typeof(IQueryService).IsAssignableFrom(typeof(TClient)))
{
}
else if (typeof(IUserService).IsAssignableFrom(typeof(TClient)))
{
}
return client;
}
}
}