PECA:
Já jsem skončil u konfigurace WCF service přes kód
public abstract class BaseService<T> where T : IService, new()
{
private static readonly Lazy<T> instance = new Lazy<T>(() => new T());
private ServiceMetadataBehavior serviceBerhavior;
private ServiceDebugBehavior serviceDebugBerhavior;
private ServiceHost serviceHost;
private string serviceName;
private string baseUrl;
protected BaseService()
{
}
public static T Instance
{
get
{
return instance.Value;
}
}
public IService GetBaseInstance()
{
return instance.Value;
}
public virtual void Start<T>(string serviceName, string baseUrl)
{
this.serviceName = serviceName;
this.baseUrl = baseUrl;
var type = typeof(T);
this.serviceBerhavior = new ServiceMetadataBehavior
{
HttpGetEnabled = true,
MetadataExporter =
{
PolicyVersion =
PolicyVersion.Policy15
}
};
this.serviceHost = new ServiceHost(type, new Uri(this.baseUrl + "/" + this.serviceName));
this.serviceHost.Description.Behaviors.Add(this.serviceBerhavior);
var debug = this.serviceHost.Description.Behaviors.Find<ServiceDebugBehavior>();
if (debug == null)
{
this.serviceHost.Description.Behaviors.Add(
new ServiceDebugBehavior { IncludeExceptionDetailInFaults = true });
}
else
{
if (!debug.IncludeExceptionDetailInFaults)
{
debug.IncludeExceptionDetailInFaults = true;
}
}
this.serviceHost.AddServiceEndpoint(type, new BasicHttpBinding(), string.Empty);
this.serviceHost.AddServiceEndpoint(ServiceMetadataBehavior.MexContractName, MetadataExchangeBindings.CreateMexHttpBinding(), "mex");
this.serviceHost.Open();
}
public virtual void Stop()
{
this.serviceHost.Close();
this.serviceHost = null;
}
public void SetBaseUrl(string baseUrl)
{
if (string.IsNullOrEmpty(this.baseUrl))
{
this.baseUrl = baseUrl;
}
else
{
throw new InvalidOperationException("BaseUrl already set");
}
}
public void SetServiceName(string serviceName)
{
if (string.IsNullOrEmpty(this.serviceName))
{
this.serviceName = serviceName;
}
else
{
throw new InvalidOperationException("ServiceName already set");
}
}
}