Currently i am migrating my class library project from .net framework 4.6.1 to .Net 5. where i am using ServiceHost class to host wcf server. As The WCF Server functionality will not be supported in .Net. what is the work around for this.
public static ServiceHost CreateServiceHost(object singleObject, string baseAddress, Type serviceContract, string endPoint, bool isNetBinding)
{
if (InstEnvironment.Instance.LogVerbose)
{
StringBuilder sb = new StringBuilder();
sb.AppendLine("ServiceUtility.CreateServiceHost() entered...");
sb.AppendFormat("\t\t\t baseAddress: {0}", baseAddress);
sb.AppendLine();
sb.AppendFormat("\t\t\t endPoint: {0}", endPoint);
sb.AppendLine();
sb.AppendFormat("\t\t\t serviceContract: {0}", serviceContract.ToString());
sb.AppendLine();
sb.AppendFormat("\t\t\t isNetBinding: {0}", isNetBinding.ToString());
LogUtility.LogMessage(sb.ToString(), LogUtility.Log.MessageType.Verbose);
sb.Length = 0;
}
Uri baseAddressUri = new Uri(baseAddress);
ServiceHost sh = new ServiceHost(singleObject, new Uri[] { baseAddressUri });
// Service Behavior
ServiceDebugBehavior debugBehavior = sh.Description.Behaviors.Find<ServiceDebugBehavior>();
if (debugBehavior == null)
{
debugBehavior = new ServiceDebugBehavior();
sh.Description.Behaviors.Add(debugBehavior);
}
debugBehavior.IncludeExceptionDetailInFaults = true;
ServiceMetadataBehavior metaDataBehavior = sh.Description.Behaviors.Find<ServiceMetadataBehavior>();
if (metaDataBehavior == null)
{
metaDataBehavior = new ServiceMetadataBehavior();
sh.Description.Behaviors.Add(metaDataBehavior);
}
CoreWCFrepo is the server-side port ofWCFfor.NET Coreand they have the sample serverhttps://github.com/CoreWCF/CoreWCF/tree/master/src/Samples/NetCoreServer
Some reasons behind it:
https://github.com/CoreWCF/CoreWCF/issues/227#issuecomment-700295498