我有一個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繳費功能
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)增加了以下按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
是否因爲數據庫位於本地SQL Server?我在某處讀到,如果我的IIS7的root帳戶與我的sql服務器(沒有密碼)使用的管理員帳戶相同,那麼應該不會有任何數據庫問題。 –