码迷,mamicode.com
首页 > Web开发 > 详细

wcf 无法激活服务,因为它不支持 ASP.NET 兼容性

时间:2014-08-23 17:37:51      阅读:599      评论:0      收藏:0      [点我收藏+]

标签:style   blog   http   color   os   使用   io   for   ar   

<system.serviceModel>
    ....
    <serviceHostingEnvironment aspNetCompatibilityEnabled="true"  multipleSiteBindingsEnabled="true"/>
  </system.serviceModel>

  如果wcf配置中aspNetCompatibilityEnabled等的配置,相应的serviceContract的实现类里面也要加对应的声明,如下所示:

[ServiceContract]
    interface IMyContract
    {
        [OperationContract]
        string MyMethod(string text);

        [OperationContract]
        string MyOtherMethod(string text);
    }

[AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Required)]
    public class MyService : IMyContract
    {
        public string MyMethod(string text)
        {
            return string.Format("Hello,{0}", text);
        }

        public string MyOtherMethod(string text)
        {
            return string.Format("Cannot call this method over wcf,{0}", text);
        }
    }

vs在创建wcf服务的时候加上了兼容模式,如果在Contract实现的时候缺少了兼容模式的声明,就会出错。

无法激活服务,因为它需要 ASP.NET 兼容性。没有未此应用程序启用 ASP.NET 兼容性。请在 web.config 中启用 ASP.NET 兼容性,或将 AspNetCompatibilityRequirementsAttribute.AspNetCompatibilityRequirementsMode 属性设置为 Required 以外的值。

兼容模式使用范例:http://www.cnblogs.com/artech/archive/2009/06/25/1511165.html
 

wcf 无法激活服务,因为它不支持 ASP.NET 兼容性

标签:style   blog   http   color   os   使用   io   for   ar   

原文地址:http://www.cnblogs.com/stealth7/p/3931508.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!