简体   繁体   English

Breeze.js返回错误'; '(分号+空格)

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

I had my Breeze code working with my WCF Data Service yesterday. 昨天我的Breeze代码正在使用我的WCF数据服务。

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! 当我在调试器中运行我的WCF数据服务时(在我的机器上)一切正常! 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? 有没有更好的方法允许使用Breeze和WCF数据服务进行跨域调用?

I was having a similar problem, getting the "; " error message and I'm also using CORS. 我遇到了类似的问题,收到“;”错误消息,我也在使用CORS。 Breeze is getting an error while trying to find the correct handler for your response. 在尝试为您的响应找到正确的处理程序时,Breeze会收到错误。 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 "; ". 它没有在返回的头文件中获取“DataServiceVersion”的值,而Breeze在response.body.message中查找错误消息,但这是空的,因此您只能获得“;”。 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. 我的修复是在他的回答中使用Ward提供的链接使用Mike Wasson CORS设置。 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. 我以前一直在使用Breeze提供的ToDo应用程序示例中使用的SimpleCorsHandler.cs类,但是没有在OPTIONS请求的“Access-Control-Allow-Headers”标头值中返回“DataServiceVersion”。 I'm not sure if I could have configured SimpleCorsHandler to fix that; 我不确定我是否可以配置SimpleCorsHandler来解决这个问题; it was eaiser to remove SimpleCorsHandler and use these two lines in the Register method of WebApiConfig.cs instead: 删除SimpleCorsHandler并在WebApiConfig.cs的Register方法中使用这两行是eaiser:

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. (有关参数的更多信息,请参阅EnableCorsAttribute文档;对于第一个使用“*”不是一个好主意,但这只是一个示例。)Breeze仍然为每个服务调用运行OPTIONS请求,然后执行GET请求,具体取决于OPTIONS响应现在包括允许DataServiceVersion标头。 The GET request gets the DataServiceVersion header (my value is 3.0) and the error is gone. GET请求获取DataServiceVersion标头(我的值为3.0),错误消失。

I would look at unintended minification and missing semicolons as suggested by @Guilherme; 按照@Guilherme的建议,我会看到意想不到的缩小和丢失的分号; you may have others besides the one after logSuccess . 除了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. 浏览器工具或Fiddler可能在这里提供帮助。

It is unlikely that your efforts at implementing CORS are the cause but it's possible. 您实施CORS的努力不太可能是原因,但这是可能的。 Have you inspected the content of Response just before you call .End() ? 您是否在调用之前检查了Response的内容.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". 我认为你已经消除了你的BreezeJS代码副本在“昨天和今天”之间发生变化的可能性。

CORS CORS

Please reconsider your handrolled CORS efforts. 请重新考虑您的手动CORS工作。 The Web API v.2 provides a CORS facility that is well described by Mike Wasson . Web API v.2提供了一个由Mike Wasson很好描述的CORS工具。 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)? 如果是这样,有没有理由你没有使用它(因为它似乎你没有使用它)?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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