2017-08-16 3 views
1

Ich erstellte eine ASP.NET-App, die einen WCF-Datenservice mit Visual Studio 2015 basierend auf the AdventureWorks2014 OLTP enthält, indem ich this walkthrough folge.Warum kann der WCF-Datenservice beim zweiten Mal nicht gestartet werden?

Wenn ich die App erstellen und in einem Debugger (auf IIS Express) ausführen, lädt der Dienst ordnungsgemäß und ich sehe die XML-Metadaten in meinem Browser angezeigt und kann weitere Anforderungen an Unterpfade, um die Zeilen meiner Datenbank anzuzeigen . Solange die Debugsitzung fortgesetzt wird, kann ich weiterhin solche Anfragen stellen.

Sobald ich den Debugger stoppen und erneut starten, ohne einen Umbau dazwischen, mein Browser stattdessen einen Fehler anzeigt:

The type 'AdventureWorks.Internal.WebService.DataService', provided as the Service attribute value in the ServiceHost directive, or provided in the configuration element system.serviceModel/serviceHostingEnvironment/serviceActivations could not be found.

[InvalidOperationException: The type 'AdventureWorks.Internal.WebService.DataService', 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) +741 
    System.ServiceModel.HostingManager.CreateService(String normalizedVirtualPath, EventTraceActivity eventTraceActivity) +1417 
    System.ServiceModel.HostingManager.ActivateService(ServiceActivationInfo serviceActivationInfo, EventTraceActivity eventTraceActivity) +53 
    System.ServiceModel.HostingManager.EnsureServiceAvailable(String normalizedVirtualPath, EventTraceActivity eventTraceActivity) +660 

[ServiceActivationException: The service '/DataService.svc' cannot be activated due to an exception during compilation. The exception message is: The type 'AdventureWorks.Internal.WebService.DataService', 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) +386 
    System.ServiceModel.Activation.HostedHttpRequestAsyncResult.End(IAsyncResult result) +174 
    System.ServiceModel.Activation.ServiceHttpHandler.EndProcessRequest(IAsyncResult result) +7 
    System.Web.CallHandlerExecutionStep.OnAsyncHandlerCompletion(IAsyncResult ar) +129 

Dies geschieht, wenn ich entweder in Visual Studio 2015 entwickeln oder 2017. Ich verwende Windows 10 mit meiner ASP.NET-App für .NET Framework 4.6.1.

DataService.svc:

<%@ ServiceHost Language="C#" Factory="System.ServiceModel.Activation.WebServiceHostFactory, System.ServiceModel.Web, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" Service="AdventureWorks.Internal.WebService.DataService" %> 

DataService.svc.cs:

namespace AdventureWorks.Internal.WebService 
{ 
    //[ServiceBehavior(IncludeExceptionDetailInFaults = true)] 
    public class DataService : DataService<AdventureWorksDatabaseEntities> 
    { 
     // This method is called only once to initialize service-wide policies. 
     public static void InitializeService(DataServiceConfiguration config) 
     { 
      config.SetEntitySetAccessRule("*", EntitySetRights.All); 
      config.DataServiceBehavior.MaxProtocolVersion = DataServiceProtocolVersion.V3; 
     } 
    } 
} 

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=169433 
    --> 
<configuration> 
    <configSections> 
    <!-- For more information on Entity Framework configuration, visit http://go.microsoft.com/fwlink/?LinkID=237468 --> 
    <section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=5.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" /> 
    </configSections> 
    <system.web> 
    <compilation debug="true" targetFramework="4.6.1" /> 
    <httpRuntime targetFramework="4.6.1" /> 
    <httpModules> 
     <add name="ApplicationInsightsWebTracking" type="Microsoft.ApplicationInsights.Web.ApplicationInsightsHttpModule, Microsoft.AI.Web" /> 
    </httpModules> 
    </system.web> 
    <system.codedom> 
    <compilers> 
     <compiler language="c#;cs;csharp" extension=".cs" type="Microsoft.CodeDom.Providers.DotNetCompilerPlatform.CSharpCodeProvider, Microsoft.CodeDom.Providers.DotNetCompilerPlatform, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" warningLevel="4" compilerOptions="/langversion:6 /nowarn:1659;1699;1701" /> 
     <compiler language="vb;vbs;visualbasic;vbscript" extension=".vb" type="Microsoft.CodeDom.Providers.DotNetCompilerPlatform.VBCodeProvider, Microsoft.CodeDom.Providers.DotNetCompilerPlatform, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" warningLevel="4" compilerOptions="/langversion:14 /nowarn:41008 /define:_MYTYPE=\&quot;Web\&quot; /optionInfer+" /> 
    </compilers> 
    </system.codedom> 
    <system.webServer> 
    <validation validateIntegratedModeConfiguration="false" /> 
    <modules> 
     <remove name="ApplicationInsightsWebTracking" /> 
     <add name="ApplicationInsightsWebTracking" type="Microsoft.ApplicationInsights.Web.ApplicationInsightsHttpModule, Microsoft.AI.Web" preCondition="managedHandler" /> 
    </modules> 
    </system.webServer> 
    <connectionStrings> 
    <add name="AdventureWorksDatabaseEntities" connectionString="metadata=res://*/DataModel.csdl|res://*/DataModel.ssdl|res://*/DataModel.msl;provider=System.Data.SqlClient;provider connection string=&quot;data source=(LocalDB)\MSSQLLocalDB;attachdbfilename=|DataDirectory|\AdventureWorksDatabase.mdf;integrated security=True;connect timeout=30;MultipleActiveResultSets=True;App=EntityFramework&quot;" providerName="System.Data.EntityClient" /> 
    </connectionStrings> 
    <entityFramework> 
    <defaultConnectionFactory type="System.Data.Entity.Infrastructure.LocalDbConnectionFactory, EntityFramework"> 
     <parameters> 
     <parameter value="v13.0" /> 
     </parameters> 
    </defaultConnectionFactory> 
    </entityFramework> 
    <system.serviceModel> 
    <serviceHostingEnvironment aspNetCompatibilityEnabled="true" /> 
    </system.serviceModel> 
</configuration> 
+1

Können Sie alle Namespaces in Ihrem Projekt überprüfen –

+0

@ Sujit.Warrier Vielen Dank! Ich habe einige der Namespaces geändert, nachdem ich die App erstellt habe. Ich habe die App neu erstellt und dieses Mal nicht mit den Namespaces, und es scheint zu funktionieren. Bitte reichen Sie eine Antwort ein, und ich werde es akzeptieren. –

Antwort

1

Dieser Fehler tritt aufgrund Namespace Inkonsistenzen. Bitte überprüfe alle Namespaces. es sollte funktionieren.

Verwandte Themen