在ServiceHost指令中作为Service属性值提供的类型' *'或在配置元素*中提供的类型无法找到

时间:2015-01-22 23:32:16

标签: c# asp.net asp.net-mvc wcf azure

我在sharepoint中有一个提供商托管的应用程序,它在本地运行没有问题。我按照本教程将其发布到azure

http://blogs.technet.com/b/sharepointdevelopersupport/archive/2013/09/05/how-to-deploy-a-provider-hosted-app-as-an-azure-site.aspx

然而,在发布webservice后,我得到了这个例外:

[InvalidOperationException: The type 'x.IntranetWeb.Services.AppEventReceiver', provided as the Service attribute value in the ServiceHost directive, or provided in the configuration element system.serviceModel/serviceHostingEnvironment/serviceActivations could not be found.]
   System.ServiceModel.Activation.ServiceHostFactory.CreateServiceHost(String constructorString, Uri[] baseAddresses) +62739
   System.ServiceModel.HostingManager.CreateService(String normalizedVirtualPath, EventTraceActivity eventTraceActivity) +1429
   System.ServiceModel.HostingManager.ActivateService(ServiceActivationInfo serviceActivationInfo, EventTraceActivity eventTraceActivity) +52
   System.ServiceModel.HostingManager.EnsureServiceAvailable(String normalizedVirtualPath, EventTraceActivity eventTraceActivity) +598

[ServiceActivationException: The service '/Services/AppEventReceiver.svc' cannot be activated due to an exception during compilation.  The exception message is: The type 'x.IntranetWeb.Services.AppEventReceiver', provided as the Service attribute value in the ServiceHost directive, or provided in the configuration element system.serviceModel/serviceHostingEnvironment/serviceActivations could not be found..]
   System.Runtime.AsyncResult.End(IAsyncResult result) +486572
   System.ServiceModel.Activation.HostedHttpRequestAsyncResult.End(IAsyncResult result) +174
   System.ServiceModel.Activation.ServiceHttpModule.EndProcessRequest(IAsyncResult ar) +345998
   System.Web.AsyncEventExecutionStep.OnAsyncEventCompletion(IAsyncResult ar) +9683593

我的web.config,我没有碰过。

<?xml version="1.0" encoding="utf-8"?>
<!--
  For more information on how to configure your ASP.NET application, please visit
  http://go.microsoft.com/fwlink/?LinkId=301880
  -->
<configuration>
  <appSettings>
    <add key="webpages:Version" value="3.0.0.0" />
    <add key="webpages:Enabled" value="false" />
    <add key="ClientValidationEnabled" value="true" />
    <add key="UnobtrusiveJavaScriptEnabled" value="true" />
    <add key="ClientId" value="xx-04e7-4caf-854a-89c20577d7da" />
    <add key="ClientSecret" value="ljguTvxHR+xx+Pl1IMg1Hjt5rsQ=" />
  </appSettings>
  <system.web>
    <compilation debug="true" targetFramework="4.5" />
    <httpRuntime targetFramework="4.5" />
    <customErrors mode="Off"/>
  </system.web>
  <runtime>
    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
      <dependentAssembly>
        <assemblyIdentity name="Newtonsoft.Json" culture="neutral" publicKeyToken="30ad4fe6b2a6aeed" />
        <bindingRedirect oldVersion="0.0.0.0-6.0.0.0" newVersion="6.0.0.0" />
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="System.Web.Optimization" publicKeyToken="31bf3856ad364e35" />
        <bindingRedirect oldVersion="1.0.0.0-1.1.0.0" newVersion="1.1.0.0" />
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="WebGrease" publicKeyToken="31bf3856ad364e35" />
        <bindingRedirect oldVersion="0.0.0.0-1.5.2.14234" newVersion="1.5.2.14234" />
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="System.Web.Helpers" publicKeyToken="31bf3856ad364e35" />
        <bindingRedirect oldVersion="1.0.0.0-3.0.0.0" newVersion="3.0.0.0" />
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="System.Web.WebPages" publicKeyToken="31bf3856ad364e35" />
        <bindingRedirect oldVersion="1.0.0.0-3.0.0.0" newVersion="3.0.0.0" />
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="System.Web.Mvc" publicKeyToken="31bf3856ad364e35" />
        <bindingRedirect oldVersion="1.0.0.0-5.2.0.0" newVersion="5.2.0.0" />
      </dependentAssembly>
    </assemblyBinding>
  </runtime>
  <system.serviceModel>
    <bindings>
      <basicHttpBinding>
        <!--Used by app for SharePoint-->
        <binding name="secureBinding">
          <security mode="Transport" />
        </binding>
      </basicHttpBinding>
    </bindings>
    <protocolMapping>
      <add binding="basicHttpBinding" scheme="https" bindingConfiguration="secureBinding" />
    </protocolMapping>
  </system.serviceModel>
  <system.webServer>
    <handlers>
      <remove name="ExtensionlessUrlHandler-Integrated-4.0" />
      <remove name="OPTIONSVerbHandler" />
      <remove name="TRACEVerbHandler" />
      <add name="ExtensionlessUrlHandler-Integrated-4.0" path="*." verb="*" type="System.Web.Handlers.TransferRequestHandler" preCondition="integratedMode,runtimeVersionv4.0" />
    </handlers>
  </system.webServer>
</configuration>

和远程事件接收器的一段代码

<%@ ServiceHost Language="C#" Debug="true" Service="x.IntranetWeb.Services.AppEventReceiver" CodeBehind="AppEventReceiver.svc.cs" %>


namespace x.IntranetWeb.Services
{
    public class AppEventReceiver : IRemoteEventService
    {

和global.asax,因为这是一个带有.svc的MVC应用程序,它可能与路由有关吗?

public class MvcApplication : System.Web.HttpApplication
    {
        protected void Application_Start()
        {
            AreaRegistration.RegisterAllAreas();
            FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
            RouteConfig.RegisterRoutes(RouteTable.Routes);
            BundleConfig.RegisterBundles(BundleTable.Bundles);
        }
    }

1 个答案:

答案 0 :(得分:1)

  1. 检查您的服务类名称,* .svc标记文件中的内容应该相同“Service = ...”
  2. 例如:

    namespace my{
    
         public class DummyService: IWebService
         {
            //implementation
         }
    }
    

    * .svc markup:&lt;%@ ServiceHost Language =“C#”Debug =“true”Service =“ my.DummyService ”CodeBehind =“myservice.svc.cs”%&gt;

    1. 尝试检查一下: WCF Web Service not working after IIS restart
    2. “有趣的是,在预编译Web服务时会触发上述错误。我尝试定期运行该服务(没有预先编译),问题不再出现。

      我在Web服务中使用了一个库,所以实际上Web服务本身根本没有任何代码。也许这就是原因。无论如何,因为没有代码,所以没有预编译也很好“

      1. 您可以为应用程序池提供服务吗?它开始了吗?