Wcf 服务发出错误ServiceHost仅支持类服务类型
我正在尝试发布一个服务,并让它使用Windows身份验证,但我甚至在尝试发布它时都遇到了一个错误,因此我还没有得到足够的提示输入用户名 这是我的错误:Wcf 服务发出错误ServiceHost仅支持类服务类型,wcf,web-services,iis,Wcf,Web Services,Iis,我正在尝试发布一个服务,并让它使用Windows身份验证,但我甚至在尝试发布它时都遇到了一个错误,因此我还没有得到足够的提示输入用户名 这是我的错误: [ArgumentException: ServiceHost only supports class service types.] System.ServiceModel.Description.ServiceDescription.GetService(Type serviceType) +16602430 System.Ser
[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中修改,该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="CAO PSA OUR"" />
</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>
这就是我的应用程序的外观:
有人看到我做错了什么吗?错误表明您正在使用接口类型来构造主机,而不是使用实现服务接口的类类型
ISubService
例如
如果这是您的用法,请将其更改为使用实现的服务类类型ISubService
ServiceHost host = new ServiceHost(
typeof(subservice.SubService), new Uri("someuri"));
如果在.svc中配置服务,则:
<%@ServiceHost Service="subservice.SubService"%>
另外,在配置文件中,将服务名称更改为服务,而不是服务合同,如下所示:
<services>
<service name="subservice.SubService">
...
...
错误表示您正在使用接口类型构造主机,而不是使用实现服务接口的类类型ISubService
例如
如果这是您的用法,请将其更改为使用实现的服务类类型ISubService
ServiceHost host = new ServiceHost(
typeof(subservice.SubService), new Uri("someuri"));
如果在.svc中配置服务,则:
<%@ServiceHost Service="subservice.SubService"%>
另外,在配置文件中,将服务名称更改为服务,而不是服务合同,如下所示:
<services>
<service name="subservice.SubService">
...
...
我不再收到该消息,我不确定它是否相关,但我现在收到了:找不到与绑定BasicHttpBinding的端点的scheme http匹配的基址。注册的基址方案是[https]顺便说一句,我正在配置。SVC需要有关部署的更多信息,以便正确理解新异常的原因。但是,作为一个快速修复方法,请尝试将配置中的
更改为
。我不确定,但在您的代码中,BasicHttpBinding没有地址。此外,您正在WebHttpbinding的地址中使用相对路径。当使用像address=“rest”这样的实时地址时,您必须指定服务的基址。我将进一步研究它。您帮助我实现了这一目标!我不再收到该消息,我不确定它是否相关,但我现在收到了:找不到与绑定BasicHttpBinding的端点的scheme http匹配的基址。注册的基址方案是[https]顺便说一句,我正在配置。SVC需要有关部署的更多信息,以便正确理解新异常的原因。但是,作为一个快速修复方法,请尝试将配置中的
更改为
。我不确定,但在您的代码中,BasicHttpBinding没有地址。此外,您正在WebHttpbinding的地址中使用相对路径。当使用像address=“rest”这样的实时地址时,您必须指定服务的基址。我将进一步研究它。您帮助我实现了这一目标!