Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
470 views
in Technique[技术] by (71.8m points)

migrate - Alternate for ServiceHost in .Net 5

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("  baseAddress: {0}", baseAddress);
            sb.AppendLine();
            sb.AppendFormat("  endPoint: {0}", endPoint);
            sb.AppendLine();
            sb.AppendFormat("  serviceContract: {0}", serviceContract.ToString());
            sb.AppendLine();
            sb.AppendFormat("  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);
        }
question from:https://stackoverflow.com/questions/65840325/alternate-for-servicehost-in-net-5

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

CoreWCF repo is the server-side port of WCF for .NET Core and they have the sample server
https://github.com/CoreWCF/CoreWCF/tree/master/src/Samples/NetCoreServer

Some reasons behind it:

This isn't a straight port of WCF Server/ServiceHost. To do a straight port would have made cross platform support almost impossible. It would have meant more code in the repo, meaning more code which needs to be maintained and a higher chance of bugs on non-windows platforms.

https://github.com/CoreWCF/CoreWCF/issues/227#issuecomment-700295498


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

2.1m questions

2.1m answers

60 comments

56.8k users

...