2017-04-03 8 views
0

Ich habe einen erholsamen .svc-less, dateilosen Dienst, der JSon-Daten zurückgibt. Es funktioniert gut, wenn es lokal ausgeführt wird, aber wenn ich in meinem lokalen IIS7 hosten, erhalte ich FehlerFileless Restful WCF funktioniert nicht, wenn es in lokalen IIS7 gehostet wird, aber lokal ausgeführt wird

Anforderungsfehler Der Server hat einen Fehler bei der Verarbeitung der Anfrage festgestellt. Weitere Informationen finden Sie in den Serverprotokollen.

Dies ist der Pfad der Web-Host-Anwendung in IIS.

localhost: 8080/AdventureWorksHost/EmployeeService/Mitarbeiter/GetEmployees

Aber funktioniert gut, wenn ich es in meinem Visual Studio laufen

localhost: 50182/employeeService/Mitarbeiter/GetEmployees

wo AdventureWorksHost ist ApplicationName gehostet unter Standardwebsite in IIS. Und EmployeeService ist der Name des Dienstes, die ich Dienst, den ich in global.asax.cs mit Standard-Endpunkten in webconfig Datei

hinzugefügt
  RouteTable.Routes.Add(new ServiceRoute("EmployeeService", new WebServiceHostFactory(), typeof(Services.EmployeeService.EmployeeService))); 

ich mehrere Vorschlag in Stackoverflow und anderen Websites für ähnliches Problem aber keine Lösung überprüft habe, arbeitet für mich.

1) Ich habe die Standardportnummer 8080 für die Standardwebsite (unter der mein Projekt gehostet wird) in IIS7 zugewiesen und sichergestellt, dass diese Portnummer nicht von der Firewall oder einer Antivirenanwendung auf meinem Computer blockiert wird. 2) Ich prüfe WCF HTTP und Nicht-HTTP-Aktivierungen, WCF Services für alle .Net Framework verfügbar in Windows-Funktionen

Windows features

3) ich gegeben habe, die Erlaubnis für IIS_IUSRS zum WebConfig meiner Anwendung hinzugefügt

4) lief ich dies in cmd prompt: aspnet_regiis.exe -iru C: \ Windows \ Microsoft.NET \ Framework \ v4.0.30319

5) ich ServiceModelReg.exe -i aus dem „% windir% lief \ Microsoft.NET \ Framework \ v3.0 \ Windows Communication Foundation "Verzeichnis zu re gister das Skript Karten

4) und 5) I verwendet forums.asp.net/t/1807824.aspx?WCF+Service+works+locally+but+returns+404+on+remote+server

6) Hinzugefügt unten nach stackoverflow.com/questions/4793127/404-when-running-net-4-wcf-service-on-iis-no-svc-file

 <system.webServer> 
      <validation validateIntegratedModeConfiguration="false"/> 
      <modules runAllManagedModulesForAllRequests="true"/> 
      </system.webServer> 

ich habe jede Lösung versucht vorgeschlagen im Internet.Nichts funktioniert auf meinem lokalen IIS7

  <?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> 
      <section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" /> 
      <!-- For more information on Entity Framework configuration, visit http://go.microsoft.com/fwlink/?LinkID=237468 --> 
      </configSections> 

      <system.diagnostics> 
       <sources> 
        <source name="System.ServiceModel" switchValue="Information, ActivityTracing" propagateActivity="true"> 
        <listeners> 
         <add name="traceListener" type="System.Diagnostics.XmlWriterTraceListener" initializeData="C:\Users\Julian Luwang\Documents\Visual Studio 2013\Projects\AdventureWorksEntityFramework\AdventureWorksHost\Log\Traces.svclog" /> 
        </listeners> 
       </source> 
       </sources> 
      </system.diagnostics> 

      <system.web> 

      <httpRuntime executionTimeout="1800000000" /> 
      <compilation debug="true" targetFramework="4.5" /> 
       <customErrors mode="On"> 
       </customErrors> 
      </system.web> 
      <system.serviceModel> 
       <standardEndpoints> 
       <webHttpEndpoint> 
        <standardEndpoint name="test" helpEnabled="true" defaultOutgoingResponseFormat="Json" automaticFormatSelectionEnabled="true" maxReceivedMessageSize="2147483647" maxBufferPoolSize="2147483647" maxBufferSize="2147483647"> 
        <readerQuotas maxArrayLength="2147483647" maxStringContentLength="2147483647" maxBytesPerRead="2147483647" maxDepth="2147483647" maxNameTableCharCount="2147483647" /> 
         <security mode="None"></security> 
       </standardEndpoint> 
       </webHttpEndpoint> 
      </standardEndpoints> 
      <serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true"> 
     </serviceHostingEnvironment> 
      <behaviors> 
       <serviceBehaviors> 
       <!--<behavior name="Secured"> 
        <serviceMetadata httpsGetEnabled="true" /> 
        <serviceDebug includeExceptionDetailInFaults="true" /> 
        <dataContractSerializer maxItemsInObjectGraph="2147483647" /> 
       </behavior>--> 
       <behavior> 
       <serviceDebug httpHelpPageEnabled="true" httpsHelpPageEnabled="false" /> 
      </behavior> 

       <behavior name="Normal"> 
        <serviceMetadata httpGetEnabled="true" /> 
        <serviceDebug includeExceptionDetailInFaults="true" /> 
        <dataContractSerializer maxItemsInObjectGraph="2147483647" /> 
       </behavior> 
        </serviceBehaviors> 
      </behaviors> 
      <bindings> 
       <webHttpBinding> 
       <!-- Binding (non-secured) --> 
       <binding name="Normal" transferMode="Streamed" maxReceivedMessageSize="2147483647" maxBufferSize="2147483647" maxBufferPoolSize="2147483647" closeTimeout="00:03:00" openTimeout="00:03:00" receiveTimeout="00:10:00" sendTimeout="00:03:00"> 
        <readerQuotas maxArrayLength="2147483647" maxStringContentLength="2147483647" maxBytesPerRead="2147483647" maxDepth="2147483647" maxNameTableCharCount="2147483647" /> 
        <security mode="None" /> 
       </binding> 
       </webHttpBinding> 
      </bindings> 

      <!--protocol mapping added--> 

       <protocolMapping> 
       <add scheme="http" binding="webHttpBinding" bindingConfiguration="Normal" /> 

      </protocolMapping> 

       </system.serviceModel> 
      <connectionStrings> 
      <add name="AdventureWorks2012Entities" connectionString="metadata=res://*/AdventureWorksEDM.csdl|res://*/AdventureWorksEDM.ssdl|res://*/AdventureWorksEDM.msl;provider=System.Data.SqlClient;provider connection string=&quot;data source=JULIAN\SQLEXPRESS;initial catalog=AdventureWorks2012;integrated security=True;trusted_connection=yes;MultipleActiveResultSets=True;App=EntityFramework&quot;" providerName="System.Data.EntityClient" /> 
      </connectionStrings> 
      <entityFramework> 
      <defaultConnectionFactory type="System.Data.Entity.Infrastructure.SqlConnectionFactory, EntityFramework" /> 
      <providers> 
       <provider invariantName="System.Data.SqlClient" type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer" /> 
      </providers> 
      </entityFramework> 
      <system.webServer> 
      <validation validateIntegratedModeConfiguration="false" /> 
       <modules runAllManagedModulesForAllRequests="true"> 

       <add name="UrlRoutingModule" type="System.Web.Routing.UrlRoutingModule, System.Web, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" /> 
      </modules> 
      <handlers> 
      <add name="UrlRoutingHandler" preCondition="integratedMode" verb="*" path="UrlRouting.axd" /> 

      </handlers> 
       <directoryBrowse enabled="true" /> 
       <defaultDocument enabled="false"> 
        <files> 
         <add value="EmployeeService" /> 
        </files> 
       </defaultDocument> 
      </system.webServer> 
     </configuration> 

Das Service

  namespace AdventureWorksHost.Services.EmployeeService 
     { 

      [AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)] 
      public class EmployeeService : IEmployeeService 
      { 

       [WebGet(UriTemplate = "Employees/GetEmployees", ResponseFormat = WebMessageFormat.Json)] 
       public List<EmployeeItem> GetEmployee() 
       { 
         try 
        { 
         List<EmployeeItem> tReturn = new List<EmployeeItem>(); 
         using (AdventureWorks2012Entities tClienEntities = new AdventureWorks2012Entities()) 
         { 
          var tEmployees = (from es in tClienEntities.Employees 
              orderby es.JobTitle 
               select new 
               { 
                es.rowguid, 
                es.BirthDate, 
                es.BusinessEntityID, 
                es.JobTitle, 
                es.NationalIDNumber, 
                es.MaritalStatus, 
                es.LoginID, 
               }).ToList(); 


          foreach (var tEmployee in tEmployees) 
          { 
           EmployeeItem tEmployeeItem = new EmployeeItem(); 
           tEmployeeItem.rowguid = tEmployee.rowguid; 
           tEmployeeItem.BusinessEntityId = tEmployee.BusinessEntityID; 
           tEmployeeItem.JobTitle = tEmployee.JobTitle; 
           tEmployeeItem.MaritalStatus = tEmployee.MaritalStatus.ToString(); 
           tEmployeeItem.NationalIDNumber = Int32.Parse(tEmployee.NationalIDNumber.ToString()); 
           tEmployeeItem.BirthDate = tEmployee.BirthDate; 
           tEmployeeItem.LoginID = tEmployee.LoginID.ToString(); 
           List<Person> Persons = new List<Person>(); 

           foreach (var tPersons in (from esp in tClienEntities.People 
                  where esp.BusinessEntityID == tEmployeeItem.BusinessEntityId 
                  orderby esp.FirstName 
                  select new 
                  { 
                   esp.rowguid, 
                   esp.FirstName, 
                   esp.MiddleName, 
                   esp.LastName, 
                   esp.PersonType, 
                   esp.Demographics 

                  })) 
           { 

            Persons.Add(new Person() 
            { 
             rowguid = tPersons.rowguid, 
             FirstName = tPersons.FirstName, 
             MiddleName = tPersons.MiddleName, 
             LastName = tPersons.LastName, 
             PersonType = tPersons.PersonType, 
             Demographics = tPersons.Demographics 
            }); 
           } 
           tEmployeeItem.Persons = Persons; 
           tReturn.Add(tEmployeeItem); 
          } 
         } 

         return tReturn; 

        } 

        catch (FaultException ex) 
        { 
         throw (ex); 
        } 

       } 
      } 

     } 

Meine Anwendung AdventureWorkHost wie folgt aussehen in meinem lokalen IIS7

Application in IIS7

+0

Ist es wegen der Datenbank im lokalen SQL Server? Ich habe irgendwo gelesen, dass, wenn mein root-Konto meines IIS7 als das gleiche Administrator-Konto ich für meinen SQL-Server (ohne ein Passwort) verwendet, dann sollte es keine Datenbank-Problem sein. –

Antwort

0

Entschlossen: Ich überprüfte der Fehler in ser Ver Logs von SQL-Server-Management-Studio. Der Fehler war

Nachricht Anmeldung fehlgeschlagen für Benutzer 'NT AUTHORITY \ NETWORK SERVICE'. Grund: Fehler beim Öffnen der explizit angegebenen Datenbank "AdventureWorks2012". [CLIENT:]

Also habe ich ein paar Dinge ausprobiert.

1) hinzugefügt NT AUTHORITY \ NETWORK SERVICE in Sicherheit Zugriff auf Ordner C: \ inetpub \ wwwroot

2) in lokalen IIS, ändert Identität des Pools Anwendung durch die gehostete Anwendung verwendet, um Netzwerk-Service von Application

3) neue Anmeldung hinzufügen NT AUTHORITY \ NETWORK SERVICE in Sicherheit des SQL MGMT STUDIO, Eigenschaften des neuen Login angeben. 4) Setzen Sie die Standarddatenbank auf Ihre Datenbank 5) Wählen Sie Datenbanken und Rollenzugehörigkeit für die neue Anmeldung als db_datareader, db_datawriter und db_owner und public 6) Legen Sie Serverrolle public und sysadmin 7) Wählen Sie Datenbank-> Sicherheit-> Benutzer (die neu erstellte Anmeldung). Öffnen Sie es 8) Satz im Besitz Schema als db_datareader, db_datawriter und db_owner 9) Stellen Sie die Rollenmitgliedschaft als db_datareader, db_datawriter und db_owner

Restart lokalen SQL Server und dann ausgeführt werden.

Verwandte Themen