2013-02-10 235 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

相關問題