2013-02-10 229 views
1

我试图发布服务并使其使用Windows身份验证,当我尝试发布服务时出现错误,所以我没有足够多获得提示输入用户名。服务发生错误ServiceHost仅支持类服务类型

这是我的错误:

[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> 

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

enter image description here

一看到我在做什么错了?

回答

6

错误表示您使用接口类型来构建主机而不是实现您的服务接口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"> 
      ... 
+0

我再也没有收到这条消息,我不确定它是否相关,但现在我得到了:无法找到与绑定BasicHttpBinding的端点匹配方案http的基地址。已注册的基地址方案是[https] – ErocM 2013-02-10 18:52:36

+0

btw我正在配置.svc – ErocM 2013-02-10 18:56:53

+0

需要有关您的部署的更多信息才能正确理解新异常的原因。但作为一个快速修复尝试改变你的配置''到''。 – Flowerking 2013-02-10 19:04:28

相关问题