WCF HTTP 504错误

时间:2012-03-21 12:19:57

标签: wcf web-services http rest web-config

我有以下问题。我正在使用实体框架连接到SQL Azure并且可以工作(我在测试项目中测试过它)。

但是当我尝试通过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.

3 个答案:

答案 0 :(得分:4)

尝试启用Tracing并查看您的请求是否超出了由此导致超时错误的默认值。

检查跟踪日志以获取有关失败原因的详细错误,然后正确执行所需步骤以增加超时值或默认大小限制

答案 1 :(得分:0)

如果您的网络环境设置为使所有HTTP流量通过代理服务器,则可能是运行IIS应用程序池的帐户不允许发送HTTP流量。作为测试,将应用程序池帐户更改为您的登录帐户,并查看WCF服务是否成功连接。 504消息通常是代理或网络问题。

答案 2 :(得分:0)

我认为这不是网络错误。问题在于服务。你可能不会从IIS收到504,而是来自Fiddler。 Read this。你可能需要增加maxItemsInObjectGraph