我有一个宁静的.svc-less,无文件服务,它返回JSon数据。如果它在本地运行它工作正常,但当我在我的本地IIS7中托管时,我得到错误
请求错误 服务器遇到处理请求的错误。有关详细信息,请参阅服务器日志。
这是IIS中Web主机应用程序的路径。
本地主机:8080 / AdventureWorksHost /的EmployeeService /雇员/装getEmployees
但是当我在我的视觉工作室中运行它时工作正常
本地主机:50182 /的EmployeeService /雇员/装getEmployees
其中AdventureWorksHost是IIS中默认网站下托管的ApplicationName。 EmployeeService是我在global.asax.cs中添加的服务的名称,其中包含webconfig文件中的标准端点
RouteTable.Routes.Add(new ServiceRoute("EmployeeService", new WebServiceHostFactory(), typeof(Services.EmployeeService.EmployeeService)));
我已经在stackoverflow和其他网站上查了几个类似问题的建议,但没有一个解决方案对我有用。
1)我在IIS7中为默认网站(托管我的项目)分配了默认端口号8080,并确保此端口号未被防火墙或计算机中的任何防病毒应用程序阻止。 2)我检查WCF HTTP和NON-HTTP激活,Windows功能中可用的所有.Net Framework的WCF服务
3)我已将IIS_IUSRS的额外权限授予我的应用程序的WebConfig
4)我在cmd提示符下运行了这个:aspnet_regiis.exe -iru C:\的Windows \ Microsoft.NET \框架\ v4.0.30319
5)我从“%windir%\ Microsoft.NET \ Framework \ v3.0 \ Windows Communication Foundation”目录运行ServiceModelReg.exe -i来注册脚本映射
4)和5)我使用forums.asp.net/t/1807824.aspx?WCF+Service+works+locally+but+returns+404+on+remote+server
6)根据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>
我已尝试在互联网上建议的每个解决方案。在我的本地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="data source=JULIAN\SQLEXPRESS;initial catalog=AdventureWorks2012;integrated security=True;trusted_connection=yes;MultipleActiveResultSets=True;App=EntityFramework"" 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中看起来像这样
答案 0 :(得分:0)
解决: 我检查了SQL Server管理工作室的服务器日志中的错误。错误是
信息 用户&#39; NT AUTHORITY \ NETWORK SERVICE&#39;登录失败。原因:无法打开显式指定的数据库&#39; AdventureWorks2012&#39;。 [客户:]
所以,我尝试了一些事情。
1)在对文件夹C的安全访问中添加了NT AUTHORITY \ NETWORK SERVICE:\ inetpub \ wwwroot
2)在本地IIS中,从applicationPoolIdentity将托管应用程序使用的应用程序池的标识更改为网络服务
3)在SQL MGMT STUDIO的安全性中添加新的登录NT AUTHORITY \ NETWORK SERVICE,指定新登录的属性。 4)将默认数据库设置为您的数据库 5)选择新登录的数据库和角色成员资格为db_datareader,db_datawriter和db_owner以及public 6)设置服务器角色public和sysadmin 7)选择database-&gt; Security-&gt; User(新创建的登录名)。打开它 8)将拥有的模式设置为db_datareader,db_datawriter和db_owner 9)将角色成员资格设置为db_datareader,db_datawriter和db_owner
重新启动本地sql server然后运行。