简体   繁体   中英

Breeze.js returns an error of '; ' (semicolon + space)

I had my Breeze code working with my WCF Data Service yesterday.

Then today, it just stopped working! When I run the query I get an error message of '; ' (one semicolon and one space) from breeze.

Everything else in the error object looks normal (I am new to breeze, so there may be something to look for that I don't know).

Any idea what could be causing this?

Update:

When I run my WCF Data Service in the debugger (on my machine) everything works! But when I run it hosted on the server, I get the above error.

The only thing I can think of is the cross domain stuff is not working right. Here is my code for cross domain:

protected void Application_BeginRequest(object sender, EventArgs e)
{
    EnableCrossDomain();
}

static void EnableCrossDomain()
{
    string origin = HttpContext.Current.Request.Headers["Origin"];
    if (string.IsNullOrEmpty(origin)) return;
    HttpContext.Current.Response.AddHeader("Access-Control-Allow-Origin", origin);
    string method = HttpContext.Current.Request.Headers["Access-Control-Request-Method"];
    if (!string.IsNullOrEmpty(method))
        HttpContext.Current.Response.AddHeader("Access-Control-Allow-Methods", method);
    string headers = HttpContext.Current.Request.Headers["Access-Control-Request-Headers"];
    if (!string.IsNullOrEmpty(headers))
        HttpContext.Current.Response.AddHeader("Access-Control-Allow-Headers", headers);
    HttpContext.Current.Response.AddHeader("Access-Control-Allow-Credentials", "true");
    if (HttpContext.Current.Request.HttpMethod == "OPTIONS")
    {
        HttpContext.Current.Response.StatusCode = 204;
        HttpContext.Current.Response.End();
    }
}

Here is an example of how I am calling it:

function getBags() {

    var bags;
    var query = breeze.EntityQuery.from('Bags');

    return manager.executeQuery(query).then(querySucceded, _queryFailed);

    function querySucceded(data) {
        bags = data.result;
        logSuccess("Retrieved Bag Data")
        return bags;
    }
}

function _queryFailed(error) {
    logError(config.appErrorPrefix + "Query Failed: " + error.message);
    throw error;
}

Is there a better way to allow cross domain calls with Breeze and WCF Data Services?

I was having a similar problem, getting the "; " error message and I'm also using CORS. Breeze is getting an error while trying to find the correct handler for your response. It is not getting a value for "DataServiceVersion" in the returned headers and Breeze is looking for an error message in response.body.message, but that is empty so you only get "; ". Ideally this error report should have some friendly text to tell you that the body message is empty or does not exist.

My fix was to use the Mike Wasson CORS setup using the link provided by Ward in his answer. I had previously been using the SimpleCorsHandler.cs class that is used in the ToDo app sample provided by Breeze, but that was not returning "DataServiceVersion" in the "Access-Control-Allow-Headers" header value for the OPTIONS request. I'm not sure if I could have configured SimpleCorsHandler to fix that; it was eaiser to remove SimpleCorsHandler and use these two lines in the Register method of WebApiConfig.cs instead:

var cors = new EnableCorsAttribute("*", "*", "*", "DataServiceVersion, MaxDataServiceVersion");
config.EnableCors(cors);

(See the EnableCorsAttribute docs for more info on the arguments; not a good idea to use "*" for the first one, but just an example here.) Breeze still runs the OPTIONS request for each service call then does a GET request depending on the OPTIONS response which now includes allowing the DataServiceVersion header. The GET request gets the DataServiceVersion header (my value is 3.0) and the error is gone.

I would look at unintended minification and missing semicolons as suggested by @Guilherme; you may have others besides the one after logSuccess .

Please review the steps in " Debugging Query Result Mysteries ", paying special attention to what is actually coming over the wire; browser tools or Fiddler may help here.

It is unlikely that your efforts at implementing CORS are the cause but it's possible. Have you inspected the content of Response just before you call .End() ? Of course you can always work backward from your commits to the point at which the code used to work. You are using version control, yes?

I take it you have eliminated the possibility that your copy of BreezeJS code changed between "yesterday and today".

CORS

Please reconsider your handrolled CORS efforts. The Web API v.2 provides a CORS facility that is well described by Mike Wasson . Did you know about this? If so, is there a reason you're not using it (as it appears that you're not using it)?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM