WCF - (504)服务器未返回此请求的响应

Kei*_*ows 22 c# asp.net wcf http-status-code-504

我有一个JSONP WCF端点,我试图找出为什么我得到504错误.

HTTP/1.1 504 Fiddler - 接收失败
内容类型:text/html
连接:close
时间戳:11:45:45:9580
ReadResponse()失败:服务器未返回此请求的响应.

我可以在我的Endpoint内部的任何地方设置一个断点,逐步执行代码,看到它成功收集响应所需的数据,点击最后一行代码,然后一旦我退出WCF调用,我就得到504错误. 这是在上周工作!

[AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)]
[ServiceContract(Name = "NegotiateService", Namespace = "http://rivworks.com/Services/2009/01/15")]
public class NegotiateService //: svcContracts.INegotiateService
{
    public NegotiateService() { }

    [OperationContract]
    [WebGet(ResponseFormat = WebMessageFormat.Json)]
    public dataObjects.NegotiateSetup GetSetup(string method, string jsonInput)
    {
        dataObjects.NegotiateSetup resultSet = new dataObjects.NegotiateSetup();

        using (RivFeedsEntities1 _dbFeed = new FeedStoreReadOnly(AppSettings.FeedAutosEntities_connString, "", "").ReadOnlyEntities())
        {
            using (RivEntities _dbRiv = new RivWorksStore(AppSettings.RivWorkEntities_connString, "", "").NegotiationEntities())
            {
                // Deserialize the input and get all the data we need...
                Newtonsoft.Json.Linq.JObject o = Newtonsoft.Json.Linq.JObject.Parse(jsonInput);
                string urlRef = String.Format("{0}", o["ref"]).Replace("\"", "");
                string clientDate = String.Format("{0}", o["dt"]).Replace("\"", "");
                string ProductID = String.Format("({0})", o["productId"]).Replace("\"", "");
                string SKU = String.Format("{0}", o["sku"]).Replace("\"", "");
                string env = String.Format("{0}", o["env"]).Replace("\"", "");

                IList<Product> efProductList = null;
                Product workingProduct = null;
                vwCompanyDetails workingCompany = null;
                bool foundItem = false;

                if (!String.IsNullOrEmpty(SKU))
                    efProductList = _dbRiv.Product.Include("Company").Where(a => a.SKU == SKU).ToList();
                else if (!String.IsNullOrEmpty(ProductID))
                    efProductList = _dbRiv.Product.Include("Company").Where(a => a.ProductId == new Guid(ProductID)).ToList();

                foreach (Product product in efProductList)
                {
                    if (String.IsNullOrEmpty(product.URLDomain))
                    {
                        var efCompany = _dbRiv.vwCompanyDetails
                                              .Where(a => a.defaultURLDomain != null && a.CompanyId == product.Company.CompanyId)
                                              .FirstOrDefault();

                        if (efCompany != null && urlRef.Contains(efCompany.defaultURLDomain))
                        {
                            foundItem = true;
                            workingProduct = product;
                            workingCompany = efCompany;
                        }
                    }
                    else
                    {
                        if (urlRef.Contains(product.URLDomain))
                        {
                            foundItem = true;
                            workingProduct = product;
                            workingCompany = _dbRiv.vwCompanyDetails
                                                   .Where(a => a.CompanyId == product.Company.CompanyId)
                                                   .FirstOrDefault();
                        }
                    }
                }

                if (foundItem)
                {
                    try
                    {
                        // Update the resultSet...
                        if (workingProduct != null && workingCompany != null)
                        {
                            string rootUrl = String.Empty;
                            try
                            {
                                rootUrl = AppSettings.RootUrl;
                            }
                            catch
                            {
                                rootUrl = env + @"/";
                            }
                            resultSet.button = workingProduct.ButtonConfig;
                            resultSet.swfSource = String.Format(@"{0}flash/negotiationPlayer.swf", rootUrl);
                            resultSet.gateway = rootUrl;
                            resultSet.productID = workingProduct.ProductId.ToString();
                            resultSet.buttonPositionCSS = workingProduct.buttonPositionCSS;
                        }
                    }
                    catch (Exception ex)
                    {
                        log.WriteLine("      ERROR: ", ex.Message);
                        log.WriteLine("STACK TRACE: ", ex.StackTrace);
                    }
                }
            }
        }
        return resultSet;
    }
}
Run Code Online (Sandbox Code Playgroud)

我的web.config:

<!-- WCF configuration -->
<system.serviceModel>
  <behaviors>
    <endpointBehaviors>
      <behavior name="JsonpServiceBehavior">
        <webHttp />
      </behavior>
    </endpointBehaviors>
  </behaviors>

  <services>
    <service name="RivWorks.Web.Service.NegotiateService">
      <endpoint address=""
              binding="customBinding"
              bindingConfiguration="jsonpBinding"
              behaviorConfiguration="JsonpServiceBehavior"
              contract="RivWorks.Web.Service.NegotiateService" />
    </service>
  </services>

  <extensions>
    <bindingElementExtensions>
      <add name="jsonpMessageEncoding" type="RivWorks.Web.Service.JSONPBindingExtension, RivWorks.Web.Service, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null" />
    </bindingElementExtensions>
  </extensions>

  <bindings>
    <customBinding>
      <binding name="jsonpBinding" >
        <jsonpMessageEncoding />
        <httpTransport manualAddressing="true"/>
      </binding>
    </customBinding>
  </bindings>    
</system.serviceModel>
Run Code Online (Sandbox Code Playgroud)

正如我所说,代码一直运行,所以我试图找出它为什么不发送响应.

Tyl*_*ler 31

对不起,我没有直接的解决方案,但在追逐与WCF相关的问题时,我发现打开WCF跟踪日志,运行方案,然后查看SvcTraceViewer.exe中的日志帮助......你将获得对堆栈的一些可见性,这可能是事情正在破坏你的地方.

您可以使用" WCF服务配置编辑器 "打开/关闭各种日志设置和级别.


Flo*_*scu 8

我只是有一个类似的问题,跟踪是识别它的唯一方法(正如@Tyler已经建议的那样).我还从服务器返回了HTTP 504,并且在Visual Studio中调试服务时没有显示任何异常.实际上,从调试器看起来服务正确地返回了响应.

在我的特定情况下,错误的原因是我的数据协定类的一个成员是枚举类型,并且值没有使用EnumMemberAttribute标记.

您可以找到有关配置在WCF跟踪的详细信息在这里和有关WCF服务的数据契约枚举这里.


Kei*_*ows 5

对于这个特殊问题,它最终成为我的连接字符串.在Web服务中,它并没有从网站的配置文件中提取.通过一点点魔术(硬编码),我得到了Context以最终激活并且系统开始工作.还没有完全通过这个504,因为我现在有其他潜在的错误弹出 - 将继续这个答案,因为我弄明白.

2010年2月1日 - 一旦我清除了连接字符串错误,我发现了一些非常快速清理的基本EF错误.它现在又重新启动了.