Fileless Restful当本地IIS7托管但本地运行的WCF不工作

问题描述:

我有一个restful .svc-less,无文件服务返回JSon数据。它工作正常,如果它在本地运行,但当我在我的本地IIS7主机,我得到错误Fileless Restful当本地IIS7托管但本地运行的WCF不工作

请求错误 服务器遇到错误处理请求。查看服务器日志获取更多详细信

这是IIS中的Web主机应用程序的路径。

本地主机:8080/AdventureWorksHost /的EmployeeService /员工/装getEmployees

但是,当我在Visual Studio中运行它工作正常

本地主机:50182 /的EmployeeService /员工/装getEmployees

其中AdventureWorksHost是ApplicationName在IIS中的默认Web站点下承载。和的EmployeeService是我服务我与标准终点的global.asax.cs加入webconfig文件

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

我已经检查了几个建议,在计算器和其他网站类似的问题,但没有解决方案适用于服务的名称我。

1)我在IIS7中为默认网站(我的项目托管在其中)分配了默认端口号8080,并确保此端口号不会被防火墙或计算机中的任何防病毒应用程序阻止。 2)我检查WCF HTTP和非HTTP激活,WCF服务用于所有.Net框架在Windows缴费功能

Windows features

3)我已经给添加权限IIS_IUSRS到WebConfig我的应用程序的

4)在我命令提示符跑这样的:ASPNET_REGIIS.EXE -iru C:\的Windows \ Microsoft.NET \框架\ v4.0.30319

5)我跑ServiceModelReg.exe -i从“%WINDIR% \ Microsoft.NET \ Framework \ v3.0 \ Windows通信基础“目录重新gister脚本映射

4)和5)我用forums.asp.net/t/1807824.aspx?WCF+Service+works+locally+but+returns+404+on+remote+server

6)增加了以下按*.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> 

我试过每种解决方案在互联网上建议。没有什么工作对我的本地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> 

的服务

  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); 
        } 

       } 
      } 

     } 

我的应用程序AdventureWorkHost看起来像这样在我的本地IIS7

Application in IIS7

+0

是否因为数据库位于本地SQL Server?我在某处读到,如果我的IIS7的root帐户与我的sql服务器(没有密码)使用的管理员帐户相同,那么应该不会有任何数据库问题。 –

解决: 我检查ser。中的错误SQL服务器管理工​​作室的版本日志。错误是

消息 用户'NT AUTHORITY \ NETWORK SERVICE'登录失败。原因:无法打开明确指定的数据库“AdventureWorks2012”。 [客户:]

所以,我试了几件事情。

1)添加的NT AUTHORITY \ NETWORK SERVICE的安全访问文件夹C:\的Inetpub \ wwwroot文件在本地IIS

2),由托管应用程序使用的应用程序池的改变身份的网络从applicationPoolIdentity

服务

3)在SQL MGMT STUDIO的安全性中添加新的登录NT AUTHORITY \ NETWORK SERVICE,指定新登录的属性。 4)将默认数据库设置为您的数据库 5)为db_datareader,db_datawriter和db_owner以及public选择用于新登录的数据库和角色成员资格6)设置服务器角色public和sysadmin 7)选择database-> Security-> User新创建的登录)。打开它 8)套装资模式作为拥有db_datareader,db_datawriter权限和db_owner 9)设置角色成员身份的db_datareader,db_datawriter权限和db_owner

重新启动本地SQL Server,然后运行。