我有以下问题。我使用实体框架连接到SQL,这是可行的(我在一个测试项目中测试了它)。
但是,当我试图通过WCF RESTful服务获得它时,它会抛出错误504。
我的经营合同:
[ServiceContract]
public interface IService
{
[OperationContract]
[WebGet(UriTemplate = "/Artikli", ResponseFormat = WebMessageFormat.Json)]
IEnumerable<Artikal> GetArtikli();
}[ServiceContract]的实现:
public class Service : IService
{
public IEnumerable<Artikal> GetArtikli()
{
using (var context = new CijenolomciEntities())
{
var result = context.Artikals.ToList();
result.ForEach(a => context.Detach(a));
return result;
}
}
}整个过程都托管在本地IIS上。我用的是Fiddler,当我试图接触它时,它会说什么
http://localhost:17916/Service.svc/Artikli 是
[Fiddler] ReadResponse() failed: The server did not return a response for this request.
WCF App.Config看起来是这样的:
<?xml version="1.0"?>
<configuration>
<connectionStrings>
<add name="CijenolomciEntities" connectionString="My_Connection_String" providerName="System.Data.EntityClient" />
</connectionStrings>
<system.web>
<compilation debug="true" targetFramework="4.0" />
</system.web>
<system.serviceModel>
<protocolMapping>
<add scheme="http" binding="webHttpBinding" />
</protocolMapping>
<behaviors>
<endpointBehaviors>
<behavior>
<webHttp />
</behavior>
</endpointBehaviors>
<serviceBehaviors>
<behavior>
<!-- To avoid disclosing metadata information, set the value below to false and remove the metadata endpoint above before deployment -->
<serviceMetadata httpGetEnabled="true"/>
<!-- To receive exception details in faults for debugging purposes, set the value below to true. Set to false before deployment to avoid disclosing exception information -->
<serviceDebug includeExceptionDetailInFaults="false"/>
</behavior>
</serviceBehaviors>
</behaviors>
<serviceHostingEnvironment multipleSiteBindingsEnabled="true" />
</system.serviceModel>
<system.webServer>
<modules runAllManagedModulesForAllRequests="true"/>
</system.webServer>
</configuration>编辑:当我试图通过浏览器访问URL时,我得到以下内容:
Request Error
The server encountered an error processing the request. See server logs for more details.发布于 2012-03-21 13:00:21
尝试启用跟踪,并查看请求是否超过了导致超时错误的默认值。
检查跟踪日志的详细错误,了解它失败的原因,然后适当地执行所需的步骤,以增加超时值或默认大小限制。
发布于 2012-03-21 12:32:00
如果您的网络环境设置为使所有HTTP流量都通过代理服务器,那么IIS应用程序池所运行的帐户很可能不允许发送HTTP流量。作为测试,将应用程序池帐户更改为您的登录帐户,并查看WCF服务是否成功连接。504消息通常是代理或网络问题。
发布于 2012-03-21 12:53:31
我不认为这是网络错误。这个问题已经解决了。可能您收到的504不是来自IIS,而是来自Fiddler。阅读这篇文章。也许你必须增加maxItemsInObjectGraph
https://stackoverflow.com/questions/9804487
复制相似问题