WCF Web服务错误:服务无法激活,因为它不支持ASP.NET兼容性
我正在尝试创build一个平静的wcf web服务。 当我尝试通过客户端连接到服务时,出现以下错误:
该服务无法激活,因为它不支持ASP.NET兼容性。 此应用程序启用了ASP.NET兼容性。 closuresweb.config中的ASP.NET兼容模式,或将AspNetCompatibilityRequirements属性添加到RequirementsMode设置为“允许”或“必需”的服务types。
其他人有问题,但他们修改了他们的web.config。 我已经实施了他们的修复程序,但问题仍然存在。 这里是我的web.config:
<system.serviceModel> <behaviors> <endpointBehaviors> <behavior name="WebBehavior" > <webHttp /> </behavior> </endpointBehaviors> <serviceBehaviors> <behavior name="MyServiceBehavior"> <serviceMetadata httpGetEnabled="true" /> <serviceDebug includeExceptionDetailInFaults="true" /> </behavior> <behavior name=""> <serviceMetadata httpGetEnabled="true" /> <serviceDebug includeExceptionDetailInFaults="false" /> </behavior> </serviceBehaviors> </behaviors> <services> <service behaviorConfiguration="MyServiceBehavior" name="myfirstwcf"> <endpoint address="ws" binding="basicHttpBinding" contract="Imyfirstwcf" /> <endpoint address="ws2" binding="wsHttpBinding" contract="Imyfirstwcf" /> <endpoint address="" behaviorConfiguration="WebBehavior" binding="webHttpBinding" contract="Imyfirstwcf" /> <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" /> </service> </services> <serviceHostingEnvironment aspNetCompatibilityEnabled= "true" multipleSiteBindingsEnabled="true" /> </system.serviceModel>
在您的主要服务上,您可以将您的服务标记为:
[AspNetCompatibilityRequirements( RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)]
它会工作:
你已经在代码中改变了这一行,或者在web.config中添加了这一行:
<system.serviceModel> <serviceHostingEnvironment aspNetCompatibilityEnabled="false" multipleSiteBindingsEnabled="true" /> </system.serviceModel>
如果有人有很多服务和服务是使用自定义的ServiceHostFactory
创build的,那么也可以在CreateServiceHost
方法中设置AspNetCompatibilityRequirementsAttribute
。
例:
public class HostFactory : ServiceHostFactory { protected override ServiceHost CreateServiceHost(Type serviceType, Uri[] baseAddresses) { var host = new ServiceHost(serviceType, baseAddresses); //other relevent code to configure host's end point etc if (host.Description.Behaviors.Contains(typeof(AspNetCompatibilityRequirementsAttribute))) { var compatibilityRequirementsAttribute = host.Description.Behaviors[typeof(AspNetCompatibilityRequirementsAttribute)] as AspNetCompatibilityRequirementsAttribute; compatibilityRequirementsAttribute.RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed; } else { host.Description.Behaviors.Add(new AspNetCompatibilityRequirementsAttribute() { RequirementsMode =AspNetCompatibilityRequirementsMode.Allowed}); } return host; } }
- 如何合并多个pdf文件(在运行时生成)?
- 如何获取部署在Azure网站上的ASP.NET 5应用程序的错误详细信息?
- 使用VirtualPathProvider从DLL加载ASP.NET MVC视图
- 如何在IIS 7,Windows 7上将ASP.NET 4.0添加为应用程序池
- 如何使用ASP.NET Web API使用非线程安全的asynchronous/等待API和模式?
- 如何获得一个string的前五个字符
- ConfigurationManager.AppSettings 每次都从web.config文件中读取?
- 如何解决ASP.NET错误“文件'nnn.aspx'没有被预编译,不能被请求。”?
- 如何计算asp.net中数据表列的总和?