您的位置:首页 > 其它

<serviceHostingEnvironment>——找不到类型“ITOO。ExamEvalTemplate.Service.WCFSercie.ExamEvalTemplateService”

2015-08-30 17:10 369 查看
好久没有调过框架了,曾经带领一个团队的时候遇到过各种各样的框架问题,只后悔自己没有好好的总结一下。现在看到了一个错误,除了感觉熟悉之外就再也没有别的了,傻傻的两个眼睛瞪着,然后就是一阵凌乱……
这不又开始做ITOO的时候,就遇到了这个阔别以后的朋友:



这个错误可以用一句话来总结,如果三分钟之内可以调出来,那就是粗来了,如果没有,那就要各种请大神还是未果的那种,有时候很邪门,有时候不知道为什么就好了,可以说它一直是一枚奇特的葩。
当然,问题就没有解决不了的,所以还是有对应的解决方案的。
于是,小乖开始用所谓的以往的经验三下五除二的没有跳出来。我也只能是呵呵了……
这个错误一般也就是两种可能,一个是配置文件,一个就是WCF层的svc文件。
先说第二个,svc文件的错误:
根据错误提示,无法激活/Service.svc服务,找不到要发布的服务类型。
<%@ ServiceHost Language="C#" Debug="true" Service="ITOO.ExamEvalTemplate.Service.WCFService.ExamEvalTemplateService" CodeBehind="Service.svc.cs"%>

所以,要看Service=“”里面的名称是否和服务命名空间相符,在CodeBehind中后缀只到.cs就可以。

再说第一个,配置文件的错误:
根据提示可能在配置元素system.serviceModel/serviceHostingEnvironment/serviceActivations中没有提供服务类型,所以在serviceModel中检查服务契约名称是否正确,服务名称是否和svc中一致。
<services>
      <service name="ITOO.ExamEvalTemplate.Service.WCFService.ExamEvalTemplateService" behaviorConfiguration="ExamEvalTemplate">
        <endpoint address="" binding="wsHttpBinding" bindingConfiguration="WsHttpBinding_Default" contract="ITOO.ExamEvalTemplate.Service.Contract.IExamEvalTemplateService" />
      </service>
    </services>
    <serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true" minFreeMemoryPercentageToActivateService="1" />

这也是以往解决这个错误的方案,可是这次都试过了然并卵。在别人的电脑上重新down一份代码就可以启动服务。我其实只是改了一下Model,所以问题就是处在这了,也就是说还有一个可能,在更改Model层的时候,Model层的应用配置文件会随着更改,如下:
<connectionStrings>
    <!--<add name="ITOOExamEntities" connectionString="metadata=res://*/TemplateModel.csdl|res://*/TemplateModel.ssdl|res://*/TemplateModel.msl;provider=System.Data.SqlClient;provider connection string="data source=192.168.24.233;initial catalog=ITOOExam;user id=ExamTemplate;password=ExamTemplate;pooling=true;max pool size=800;min pool size=300;MultipleActiveResultSets=True;App=EntityFramework"" providerName="System.Data.EntityClient" />-->
    <add name="ITOOExamEntities1" connectionString="metadata=res://*/TemplateModel.csdl|res://*/TemplateModel.ssdl|res://*/TemplateModel.msl;provider=System.Data.SqlClient;provider connection string="data source=192.168.24.233;initial catalog=ITOOExam;persist security info=True;user id=sa;password=123456;MultipleActiveResultSets=True;App=EntityFramework"" providerName="System.Data.EntityClient" />
  </connectionStrings>

重新添加实体的时候会添加一条心的配置连接数据库字符串,当然如果忘记更改WCF层配置文件的数据库连接字符串的时候也是不行的。
<connectionStrings>
    <!--<add name="ITOOExamEntities1" connectionString="metadata=res://*/TemplateModel.csdl|res://*/TemplateModel.ssdl|res://*/TemplateModel.msl;provider=System.Data.SqlClient;provider connection string="data source=192.168.24.233;initial catalog=ITOOExam;user id=ExamTemplate;password=ExamTemplate;pooling=true;max pool size=800;min pool size=300;MultipleActiveResultSets=True;App=EntityFramework"" providerName="System.Data.EntityClient" />-->
    <add name="ITOOExamEntities1" connectionString="metadata=res://*/TemplateModel.csdl|res://*/TemplateModel.ssdl|res://*/TemplateModel.msl;provider=System.Data.SqlClient;provider connection string="data source=192.168.24.233;initial catalog=ITOOExam;persist security info=True;user id=sa;password=123456;MultipleActiveResultSets=True;App=EntityFramework"" providerName="System.Data.EntityClient" />
  </connectionStrings>


如果这些方法都还不行,那你可以重启一下项目,也是有可能存在端口被占用的情况。

貌似罗嗦了很久,还没有说到重点,因为报的错误一直是围绕着serviceHostingEnvironment,所以想好好的学习一下它,<serviceHostingEnvironment>请见下篇博客……
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: