views:

2724

answers:

2

I have a JSONP WCF Endpoint and am trying to track down why I am getting a 504 error.

HTTP/1.1 504 Fiddler - Receive Failure
Content-Type: text/html
Connection: close
Timestamp: 11:45:45:9580
ReadResponse() failed: The server did not return a response for this request.

I can set a breakpoint anywhere inside of my Endpoint, step through code, see it successfully gather the data required for the response, hit the final line of code, then as soon as I step out of the WCF call I get a 504 error. This was working last week!

[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;
    }
}

My 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>

As I said, the code runs all the way through so I am trying to figure out why it is not sending a response.

+3  A: 

Hi, I'm sorry I don't have a direct solution for you, but when chasing down WCF-related issues, I've found that turning on the WCF trace logs, running through the scenario, then going over the logs in SvcTraceViewer.exe helps... you'll get some visibility into the stack which is likely where things are breaking down on you.

You can use the "WCF Service Configuration Editor" to turn on/off the various log settings and levels.

Tyler
I am seeing some weird behavior on the Entity Framework not loading the Context requested. <grrrr/>
Keith Barrows
This helped me identify and address my problem immediately! I actually didn't even know this was specifically a WCF issue. Thanks!
Chris Gillum
+2  A: 

For this particular problem it ended up being my connection string. Being in a web service, it was not pulling from the web site's config file. With a little bit of magic (hard coding) I got the Context to finally activate and the system started working. Not fully through this 504 yet as I have other underlying errors now popping up - will continue this answer as I figure it out.

2/1/2010 - Once I cleared up the connection string errors I found a couple basic EF errors that were very quickly cleaned up. It is now up and running again.

Keith Barrows