【问题标题】:service is giving an error ServiceHost only supports class service types服务出错 ServiceHost 仅支持类服务类型
【发布时间】:2013-02-10 18:08:04
【问题描述】:

我正在尝试发布一项服务并让它使用 Windows 身份验证,但我什至在尝试发布它时遇到了一个错误,所以我还没有走得足够远,无法提示输入用户名。

这是我的错误:

[ArgumentException: ServiceHost only supports class service types.]
   System.ServiceModel.Description.ServiceDescription.GetService(Type serviceType) +16602430
   System.ServiceModel.ServiceHost.CreateDescription(IDictionary`2& implementedContracts) +80
   System.ServiceModel.ServiceHostBase.InitializeDescription(UriSchemeKeyedCollection baseAddresses) +174
   System.ServiceModel.ServiceHost..ctor(Type serviceType, Uri[] baseAddresses) +475
   System.ServiceModel.Activation.ServiceHostFactory.CreateServiceHost(Type serviceType, Uri[] baseAddresses) +43
   System.ServiceModel.Activation.ServiceHostFactory.CreateServiceHost(String constructorString, Uri[] baseAddresses) +530
   System.ServiceModel.HostingManager.CreateService(String normalizedVirtualPath) +1413
   System.ServiceModel.HostingManager.ActivateService(String normalizedVirtualPath) +50
   System.ServiceModel.HostingManager.EnsureServiceAvailable(String normalizedVirtualPath) +1172

[ServiceActivationException: The service '/subservice/ISubService.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) +901424
   System.ServiceModel.Activation.HostedHttpRequestAsyncResult.End(IAsyncResult result) +178638
   System.Web.CallHandlerExecutionStep.OnAsyncHandlerCompletion(IAsyncResult ar) +136

我已经对此进行了一百次研究,但我对发布服务的经验很少。一旦他们建成,我就与他们合作过,只是从未发布过。

这是我的 web.config,我从另一个可以正常发布的 web.config 修改:

<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <appSettings>
    <add key="log4net.Internal.Debug" value="true" />
  </appSettings>
  <system.web>
    <compilation targetFramework="4.0" debug="true">
      <assemblies>
        <add assembly="System.Data.Entity, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
      </assemblies>
    </compilation>
    <caching>
      <outputCacheSettings>
        <outputCacheProfiles>
          <add name="DefaultCache" duration="60" varyByParam="none" />
        </outputCacheProfiles>
      </outputCacheSettings>
    </caching>
  </system.web>
  <system.serviceModel>
    <serviceHostingEnvironment multipleSiteBindingsEnabled="true" aspNetCompatibilityEnabled="true" />
    <bindings>
      <basicHttpBinding>
        <binding name="BasicHttpEndpointBinding">
          <security mode="None">
            <!-- Basic <security mode="Transport"> -->
            <!-- To use Basic auth, just comment Windows and use this, but you need to configure basic in IIS as well -->
            <!-- <transport clientCredentialType="Basic" /> -->
            <transport clientCredentialType="None" />
          </security>
        </binding>
      </basicHttpBinding>
      <webHttpBinding>
        <binding name="default">
          <security mode="None">
            <!-- Basic <security mode="Transport"> -->
            <!-- To use Basic auth, just comment Windows and use this -->
            <!-- <transport clientCredentialType="Basic" /> -->
            <transport clientCredentialType="None" />
          </security>
        </binding>
      </webHttpBinding>
    </bindings>
    <behaviors>
      <serviceBehaviors>
        <behavior>
          <!-- 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>
      <endpointBehaviors>
        <behavior name="restBehavior">
          <webHttp />
        </behavior>
      </endpointBehaviors>
    </behaviors>
    <services>
      <service name="subservice.ISubService">
        <endpoint binding="basicHttpBinding" bindingConfiguration="BasicHttpEndpointBinding" contract="subservice.ISubService">
          <identity>
            <dns value="localhost" />
          </identity>
        </endpoint>
        <endpoint address="rest" binding="webHttpBinding" bindingConfiguration="default" behaviorConfiguration="restBehavior" contract="subservice.ISubService">
          <identity>
            <dns value="localhost" />
          </identity>
        </endpoint>
      </service>
    </services>
  </system.serviceModel>
  <system.webServer>
    <modules runAllManagedModulesForAllRequests="true" />
    <httpProtocol>
      <customHeaders>
        <add name="p3p" value="CP=&quot;CAO PSA OUR&quot;" />
      </customHeaders>
    </httpProtocol>
  </system.webServer>

</configuration>

我的 web.release.config 中没有任何内容:

<?xml version="1.0"?>

<!-- For more information on using web.config transformation visit http://go.microsoft.com/fwlink/?LinkId=125889 -->

<configuration xmlns:xdt="http://schemas.microsoft.com/XML-Document-Transform">

  <system.web>
    <compilation xdt:Transform="RemoveAttributes(debug)" />
  </system.web>

</configuration>

这是我的应用程序的样子:

有人知道我做错了吗?

【问题讨论】:

    标签: wcf web-services iis


    【解决方案1】:

    错误表明您使用 Interface 类型来构造主机,而不是实现您的服务接口 ISubService 的类类型。

    例如。

    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"%>
    

    同样在您的配置文件中,将服务名称更改为服务而不是服务合同:

       <services>
              <service name="subservice.SubService">
              ...
    

    【讨论】:

    • 我不再收到该消息,我不确定它是否相关,但我现在收到了:找不到与绑定 BasicHttpBinding 的端点的方案 http 匹配的基地址.注册的基地址方案是 [https]
    • 顺便说一句,我正在配置 .svc
    • 需要有关您的部署的更多信息,以正确了解新异常的原因。但作为一个快速修复尝试将您的配置 &lt;security mode="None"&gt; 更改为 &lt;security mode="Transport" /&gt;
    • 我不确定,但在您的代码中,BasicHttpBinding 没有地址。此外,您在 WebHttpbinding 的地址中使用了相对路径。当使用像 address="rest" 这样的真实地址时,您必须指定服务的基地址。
    • 我会再研究一下,你帮我搞到这么远 tyvm!
    猜你喜欢
    • 2012-04-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-07-14
    相关资源
    最近更新 更多