static void Main(string[] args)
{
DynamicHost host = new DynamicHost();
// Build Service Assembly
Assembly memoryAssembly = host.GetContractAssembly();
// Get all needed parameters
String contractFullName = String.Format("{0}.{1}",
ConfigurationManager.AppSettings["NamespaceToGenerate"],
ConfigurationManager.AppSettings["FacadeName"]);
String serviceFullName = String.Format("{0}.{1}", ConfigurationManager.AppSettings["NamespaceToGenerate"],
ConfigurationManager.AppSettings["ServiceName"]);
Type contract = memoryAssembly.GetType(contractFullName);
Type service = memoryAssembly.GetType(serviceFullName);
// Create the WCF Service Host
ServiceHost sh = new ServiceHost(service);
sh.AddServiceEndpoint(contract, new NetTcpBinding(),
String.Format("{0}/{1}", ConfigurationManager.AppSettings["FacadeUrl"], contractFullName));
// Add HttpGet Metadata
ServiceMetadataBehavior metadataBehavior = sh.Description.Behaviors.Find<ServiceMetadataBehavior>();
if (metadataBehavior == null)
metadataBehavior = new ServiceMetadataBehavior();
sh.Description.Behaviors.Add(metadataBehavior);
}
// Add metadata behavior to existing behaviors
ServiceDebugBehavior serv = sh.Description.Behaviors.Find<ServiceDebugBehavior>();
if (serv == null)
serv = new ServiceDebugBehavior();
// Generate detailed faults. ONLY FOR DEBUG PURPOSE!
serv.IncludeExceptionDetailInFaults = true;
// {"HTTP could not register URL http://+:1111/THB.Sample.ServiceContracts.IFacade/HttpGetUrl/.
// Your process does not have access rights to this namespace (see http://go.microsoft.com/fwlink/?LinkId=70353
// for details)."}
// C:\Windows\system32>netsh http add urlacl url=http://+:1111/ user=bewise\fcolin
// URL reservation successfully added
metadataBehavior.HttpGetEnabled = true;
metadataBehavior.HttpGetUrl = new Uri(String.Format(ConfigurationManager.AppSettings["HttpGetUrl"],
contractFullName));
// Add MexEndPoint
sh.AddServiceEndpoint(typeof(IMetadataExchange), MetadataExchangeBindings.CreateMexTcpBinding(),
String.Format(ConfigurationManager.AppSettings["MexTcpEndPoint"], contractFullName));
sh.Open();
Console.WriteLine("Facade service started!");
Console.ReadLine();
sh.Close();