WCF异常:ServiceHost仅支持类服务类型--从windows服务运行时

WCF异常:ServiceHost仅支持类服务类型--从windows服务运行时,wcf,windows-services,Wcf,Windows Services,我是wcf的新手。我面临此错误ServiceHost仅支持类服务类型 在这里,我会说我正在做和运行我的win服务和wcf在一起。 我添加了windows服务项目,还为win服务项目中的wcf添加了一些参考,如System.ServiceModel。当我试图从win service运行wcf服务时,我收到一个名为的错误,ServiceHost仅支持类服务类型 我搜索并得到了许多类似的答案 ServiceHost host = new ServiceHost(

我是wcf的新手。我面临此错误
ServiceHost仅支持类服务类型

在这里,我会说我正在做和运行我的win服务和wcf在一起。 我添加了windows服务项目,还为win服务项目中的wcf添加了一些参考,如
System.ServiceModel
。当我试图从win service运行wcf服务时,我收到一个名为的错误,ServiceHost仅支持类服务类型

我搜索并得到了许多类似的答案

ServiceHost host = new ServiceHost(
                       typeof(subservice.ISubService), new Uri("someuri"));
如果这是您的用法,请将其更改为使用ISubService的已实现服务类类型

ServiceHost host = new ServiceHost(
                       typeof(subservice.SubService), new Uri("someuri"));
如果在.svc中配置服务,则:

<%@ServiceHost Service="subservice.SubService"%>
这里我给出了我试图从win服务运行的代码 这是我的wcf服务配置条目

在这里,我粘贴了所有相关代码,我想请求一些代码。请查看我的代码,并告诉我为什么在尝试从windows服务运行时会收到错误消息,如
ServiceHost仅支持类服务类型。我在代码中遗漏了什么吗

我是否应该为wcf类库创建一个单独的项目,为windows服务创建另一个单独的项目,因为我在那里有一个项目,我有wcf和windows服务的文件


因此,寻找建议,比如我需要在代码中纠正什么,作为一个结果,win服务可以启动wcf服务。请提供帮助。

检查标记中服务的定义:

右键单击SagePartInsertion.svc文件并选择“查看标记”

确保服务是接口的实现,如下所示:

<%@ ServiceHost Language="C#" Debug="true" Service="SageDataImportWCF.SagePartInsertion" CodeBehind="SagePartInsertion.svc.cs" %>

过去它失败是因为我引用了接口

namespace SageDataImportWCF
{
    [ServiceContract]
        public interface ISagePart
        {

            [OperationContract]
            string SageInsertionProcess(string SQLConnectionString, string CountryCode);

            // TODO: Add your service operations here
        }

     public class SagePartInsertion : ISagePart
     {
            public string SageInsertionProcess(string SQLConnectionString, string CountryCode)
            {
            }
     }
}
namespace SageDataImportWCF
{
    public partial class SageDateInsertionService : ServiceBase
    {
        #region Local Variables
        ServiceHost serviceHost;
        #endregion

        #region Constructor
        public SageDateInsertionService()
        {
            InitializeComponent();
            serviceHost = null;
            ServiceName = "Sage DataInsertion Service";
        }
        #endregion

        protected override void OnStart(string[] args)
        {
            string strAdrHTTP = "http://192.168.6.2:11000/SagePartInsertion";
            if (serviceHost != null)
            {
                serviceHost.Close();
            }
            serviceHost = new ServiceHost(typeof(SageDataImportWCF.SagePartInsertion));
            serviceHost.AddServiceEndpoint(typeof(SageDataImportWCF.ISagePart), new BasicHttpBinding(), strAdrHTTP);
            ServiceMetadataBehavior behaviour = new ServiceMetadataBehavior();
            behaviour.HttpGetEnabled = true;
            serviceHost.Description.Behaviors.Add(behaviour);
            serviceHost.Open();
        }

        protected override void OnStop()
        {
            if (serviceHost != null)
            {
                serviceHost.Close();
                serviceHost = null;
            }
        }
    }
}
<configuration>
    <system.serviceModel>
        <services>
            <service name="SageDataImportWCF.SagePartInsertion" behaviorConfiguration="SageBehavior">
                <endpoint address="http://localhost:9001/SagePartInsertion"  contract="SageDataImportWCF.ISagePart" binding="basicHttpBinding"/>
            </service>
        </services>
        <behaviors>
            <serviceBehaviors>
                <behavior name="SageBehavior">
                    <!-- To avoid disclosing metadata information, set the value below to false and remove the metadata endpoint above before deployment -->
                    <serviceMetadata httpGetEnabled="true"/>
                    <!-- To receive exception details in faults for debugging purposes, set the value below to true.  Set to false before deployment to avoid disclosing exception information -->
                    <serviceDebug includeExceptionDetailInFaults="true"/>
                </behavior>
            </serviceBehaviors>
        </behaviors>
        <serviceHostingEnvironment multipleSiteBindingsEnabled="true" />
    </system.serviceModel>
    <system.webServer>
        <modules runAllManagedModulesForAllRequests="true"/>
    </system.webServer>
</configuration>
<%@ ServiceHost Language="C#" Debug="true" Service="SageDataImportWCF.SagePartInsertion" CodeBehind="SagePartInsertion.svc.cs" %>