无法初始化OData。使用Breeze,需要支持远程OData服务

时间:2013-06-13 20:07:21

标签: javascript wcf odata breeze

我正在尝试使用breeze来调用wcf服务,bij config breeze使用OData。但我仍然得到错误:

Unable to initialize OData, Needed to support remote OData services 

我也尝试过:breeze.config.initializeAdapterInstance("dataService", "OData");

下面我有想要使用的html页面。

<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title></title>
    <script src="../Scripts/jquery-2.0.2.js"></script>
    <script src="../Scripts/knockout-2.2.1.debug.js"></script>
    <script src="../Scripts/q.js"></script>
    <script src="../Scripts/breeze.debug.js"></script>

    <script>
       breeze.core.config.setProperties({
            // the OData provider
            remoteAccessImplementation: breeze.entityModel.remoteAccess_odata,
            // this is the Knockout provider but we also provide a Backbone provider
            //  and we have others on the way
            trackingImplementation: breeze.entityModel.entityTracking_ko
        });


        var myServiceName =             "http://597de06c06404b47b1f1f592c56f6753.cloudapp.net/GoedendoelDataService.svc/?      $format=json";
        var em = new breeze.entityModel.EntityManager( {serviceName: myServiceName });

        var query = breeze.entityModel.EntityQuery.from("Goedendoel")
            .where("title", "startsWith", "G")
            .orderBy("title");

        em.executeQuery(query).then(function(data) {
            // process the results here.
            ko.applyBindings(data);
         }).fail(function (e) {
            alert(e);
        });

    </script>
 </head>
 <body>
    <p data-bind="visible: !results">Fetching data ... </p>
     <ul data-bind="foreach: results, visible: results" style="display: none">
        <li>
            <span data-bind="text:title"></span>
        </li>
     </ul>
</body>
 </html>

1 个答案:

答案 0 :(得分:7)

对于Breeze的OData支持,您还需要Microsoft的datajs库。此处还有更多信息:Breeze OData