ServiceHost仅支持类服务类型

问题描述:

我正在创建一个WCF服务,它似乎昨天在VS测试客户端上运行良好,但今天它似乎在我尝试更改web.config文件后引发此错误。ServiceHost仅支持类服务类型

下面

是代码和配置文件:

using System; 
using System.Collections.Generic; 
using System.Linq; 
using System.Runtime.Serialization; 
using System.ServiceModel; 
using System.ServiceModel.Web; 
using System.Text; 

namespace TSService 
{ 
    interface name "IService1" in both code and config file together. 
    [ServiceContract] 
    public interface ITSService 

    [OperationContract] 
    List<Sel_Test> RunScript(List<SName> SNamesToRun, int LogPathIndex, RunEnvironment EnvironmentName, BOptions BType, NavOption NavEnum); 

} 

[DataContract] 
    public class STest 
    { 
     [DataMember] 
     public ScriptName SName { get; set; } 
     [DataMember] 
     public BOptions BTypeUsed { get; set; } 
     [DataMember] 
     public int SResult { get; set; } 
    } 

    [DataContract(Name= "SName")] 
    public enum SName 
    { 
     [EnumMember] 
     PXXXX1, 
     [EnumMember] 
     PXXXX2, 
     [EnumMember] 
     PXXXX3, 
     [EnumMember] 
     PXXXX4 

    } 

    [DataContract] 
    public enum NavOption 
    { 
     [EnumMember] 
     ContinueToNext, 
     [EnumMember] 
     Skip, 
     [EnumMember] 
     SignIn, 
     [EnumMember] 
     Registration 
    } 

    [DataContract] 
    public enum BOptions 
    { 
     [EnumMember] 
     FAA1, 
     [EnumMember] 
     ReFi, 
     [EnumMember] 
     RIE 
    } 

    [DataContract] 
    public enum RunEnvironment 
    { 
     [EnumMember] 
     D, 
     [EnumMember] 
     Q, 
     [EnumMember] 
     S, 
     [EnumMember] 
     P 
    } 
    [DataContract] 
    public enum PType 
    { 
     [EnumMember] 
     MAPD, 
     [EnumMember] 
     PDP, 
     [EnumMember] 
     MA, 
     [EnumMember] 
     Mgap 
    }; 
} 

在配置文件中我有:

<system.serviceModel> 

    <behaviors> 
     <serviceBehaviors> 
     <behavior name="TSServiceBehavior"> 
      <!-- To avoid disclosing metadata information, set the values below to false before deployment --> 
      <serviceMetadata httpGetEnabled="true" httpsGetEnabled="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> 

    <services> 
     <service name="TSService.ITSService" behaviorConfiguration="TSServiceBehavior"> 
     <endpoint address="" 
        binding ="basicHttpBinding" 
        contract="TSService.ITSService" /> 

     <endpoint address="mex" 
        binding="mexHttpsBinding" 
        contract="IMetadataExchange" /> 
     </service> 
    </services> 


    <bindings> 
     <basicHttpBinding> 
     <binding name ="TSServiceBinding" receiveTimeout="00:20:00" sendTimeout="00:20:00"> 
      <security mode="None"/> 
     </binding> 
     </basicHttpBinding> 
    </bindings> 


    <!--<protocolMapping> 
     <add binding="basicHttpsBinding" scheme="https" /> 
    </protocolMapping>--> 
    <serviceHostingEnvironment aspNetCompatibilityEnabled="False" multipleSiteBindingsEnabled="true"/> 
    </system.serviceModel> 
    <system.webServer> 
    <modules runAllManagedModulesForAllRequests="true"/> 
    <!-- 
     To browse web app root directory during debugging, set the value below to true. 
     Set to false before deployment to avoid disclosing web app folder information. 
     --> 
    <directoryBrowse enabled="true"/> 
    </system.webServer> 



    <system.diagnostics> 
    <sources> 
     <source name="System.ServiceModel" 
       switchValue="Information, ActivityTracing" 
       propagateActivity="true"> 
     <listeners> 
      <add name="traceListener" 
       type="System.Diagnostics.XmlWriterTraceListener" 
       initializeData= "c:\log\Traces.svclog" /> 
     </listeners> 
     </source> 
    </sources> 
    </system.diagnostics> 
在SVC标记

我有:

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

的错误,我在运行VS WCFTest客户端时得到:

Error: Cannot obtain Metadata from http://localhost:55178/TSService.svc If this is a Windows (R) Communication Foundation service to which you have access, please check that you have enabled metadata publishing at the specified address. For help enabling metadata publishing, please refer to the MSDN documentation at http://go.microsoft.com/fwlink/?LinkId=65455.WS-Metadata Exchange Error URI: http://localhost:55178/TSService.svc Metadata contains a reference that cannot be resolved: 'http://localhost:55178/TSService.svc'. The requested service, 'http://localhost:55178/TSService.svc' could not be activated. See the server's diagnostic trace logs for more information.HTTP GET Error URI: http://localhost:55178/TSService.svc There was an error downloading 'http://localhost:55178/TSService.svc'. The request failed with the error message:-- 
Server Error in '/' Application. 
-------------------------------------------------------------------------------- 

ServiceHost only supports class service types. 
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. 

Exception Details: System.ArgumentException: ServiceHost only supports class service types. 

Source Error: 

An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below. 

Stack Trace: 

[ArgumentException: ServiceHost only supports class service types.] System.ServiceModel.Description.ServiceDescription.GetService(Type serviceType) +12912843 System.ServiceModel.ServiceHost.CreateDescription(IDictionary`2& implementedContracts) +58 System.ServiceModel.ServiceHostBase.InitializeDescription(UriSchemeKeyedCollection baseAddresses) +146 System.ServiceModel.ServiceHost.InitializeDescription(Type serviceType, UriSchemeKeyedCollection baseAddresses) +46 System.ServiceModel.ServiceHost..ctor(Type serviceType, Uri[] baseAddresses) +146 System.ServiceModel.Activation.ServiceHostFactory.CreateServiceHost(Type serviceType, Uri[] baseAddresses) +30 System.ServiceModel.Activation.ServiceHostFactory.CreateServiceHost(String constructorString, Uri[] baseAddresses) +494 System.ServiceModel.HostingManager.CreateService(String normalizedVirtualPath, EventTraceActivity eventTraceActivity) +1434 System.ServiceModel.HostingManager.ActivateService(ServiceActivationInfo serviceActivationInfo, EventTraceActivity eventTraceActivity) +52 System.ServiceModel.HostingManager.EnsureServiceAvailable(String normalizedVirtualPath, EventTraceActivity eventTraceActivity) +598[ServiceActivationException: The service '/TSService.svc' cannot be activated due to an exception during compilation. The exception message is: ServiceHost only supports class service types..] System.Runtime.AsyncResult.End(IAsyncResult result) +495736 System.ServiceModel.Activation.HostedHttpRequestAsyncResult.End(IAsyncResult result) +178 System.ServiceModel.Activation.ServiceHttpModule.EndProcessRequest(IAsyncResult ar) +348782 System.Web.AsyncEventExecutionStep.OnAsyncEventCompletion(IAsyncResult ar) +9662977 



-------------------------------------------------------------------------------- 
Version Information:ÿMicrosoft .NET Framework Version:4.0.30319; ASP.NET Version:4.0.30319.18034 --. 
+0

好吧,我通过在标记中将ITSService更改为TSSErvice来摆脱了此错误。但是现在我得到了“无法从...获取元数据”错误。 – ipoh 2013-02-14 16:24:20

将此标记为基于评论回答 - “我通过将标记中的ITSService更改为TSSErvice来摆脱此错误。”

+0

在这里完全相同的问题更彻底的答案:http://*.com/questions/9863483/servicehost-only-supports-class-service-types – Kjellski 2013-09-25 11:38:54