AngularJS-BreezeJS - 405方法不允许

时间:2014-06-23 12:53:57

标签: angularjs breeze

我已经创建了一个OData服务,但是当BreezeJS错误查询时。 以下是我的查询结果

http://115.78.161.4:96/odata/ShArticles

Breeze Config: breeze.config.initializeAdapterInstance(' dataService',' webApiOData',true);

(function () {
    'use strict';
    var serviceId = 'entityManagerFactoryOData';
    angular.module('myApp').factory(serviceId, ['breeze', emFactory]);
    function emFactory(breeze) {
        configureBreeze();
        var serviceRoot = window.location.protocol + '//' + '115.78.161.4:96'+ '/';
        var serviceName = serviceRoot + 'odata/';

        var factory = {
            newManager: newManager,
            serviceName: serviceName
        };
        return factory;

        function configureBreeze() {
            breeze.config.initializeAdapterInstance('dataService', 'webApiOData', true);
            //dùng web API Odata để query và save           
            //breeze.NamingConvention.camelCase.setAsDefault();//chuyển đổi giữa server-side PascalCase và client-side camelCase
        }
        //Tạo new instance(s) của BreezeJS EntityManager để dùng trong một 'datacontext' service
        function newManager() {          
            var mgr = new breeze.EntityManager(serviceName);
            return mgr;
        }
    }
})();

代码查询

 function getShArticles(forceRefresh) {
            var count;
            if (forceRefresh) {
                if (manager.hasChanges()) {
                    count = getChangesCount();
                    manager.rejectChanges();//trả về giá trị ban đầu trong cache cho các giá trị bị thay đổi nhưng không được lưu
                    logWarning('Có ' + count + ' bị thay đổi', null, true);
                }
            }
            //Nếu không forceRefresh,cân nhắc nhận từ cache hơn là truy vấn giá trị mới từ xa
            return breeze.EntityQuery.from('ShArticles')
                    .using(manager).execute()
                    .then(success).catch(failed);
            function success(response) {
                count = response.results.length;
                logSuccess('Nhận ' + count + ' dòng', response, true);
                return response.results;
            }
            function failed(error) {
                var message = error.message || "Truy vấn bảng ShArticles lỗi";
                logError(message, error, true);
            }
        }

控制器API

    public class ShArticlesController: ODataController
    {
        private static ODataValidationSettings _validationSettings = new ODataValidationSettings();
        vl360Context db = new vl360Context();
        // GET odata/ShArticles
        [Queryable]
        public IQueryable<ShArticle> GetShArticles()
        {
            return db.ShArticles;
        }
        // GET odata/ShArticles(5)
        [Queryable]
        public SingleResult<ShArticle> GetShArticle([FromODataUri] int key)
        {
            return SingleResult.Create(db.ShArticles.Where(x => x.ArticleID == key));

        }
    }

真诚地感谢您对任何帮助的评论

代码注册EdmBuilder:

public static void Register(HttpConfiguration config)
        {
            config.MapHttpAttributeRoutes();

            config.Routes.MapODataRoute(
                routeName: "odata",
                routePrefix: "odata",
                model: EdmBuilder.GetEdm<vl360Context>(),
                batchHandler: new DefaultODataBatchHandler(GlobalConfiguration.DefaultServer)
                );

            config.Routes.MapHttpRoute(
                name: "DefaultApi",
                routeTemplate: "api/{controller}/{id}",
                defaults: new { id = RouteParameter.Optional }
            );

            // Uncomment the following line of code to enable query support for actions with an IQueryable or IQueryable<T> return type.
            // To avoid processing unexpected or malicious queries, use the validation settings on QueryableAttribute to validate incoming queries.
            // For more information, visit http://go.microsoft.com/fwlink/?LinkId=279712.
            config.EnableQuerySupport();

Webconfig:

<?xml version="1.0"?>
<!--
  For more information on how to configure your ASP.NET application, please visit
  http://go.microsoft.com/fwlink/?LinkId=169433
  -->
<configuration>
  <configSections>
    <section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false"/>
    <!-- For more information on Entity Framework configuration, visit http://go.microsoft.com/fwlink/?LinkID=237468 -->
  </configSections>
  <connectionStrings>
    <!--<add name="vl360Context" connectionString="Data Source=(LocalDB)\v11.0;AttachDbFilename=E:\PROJECT_TRELL\AJSolution\AJSolution\OdataService\App_Data\360vl.mdf;Integrated Security=True;Connect Timeout=30" providerName="System.Data.SqlClient" />-->
    <!--<add name="vl360Context" connectionString="Data Source=(LocalDB)\v11.0;AttachDbFilename=|DataDirectory|\360vl.mdf;Integrated Security=True;Connect Timeout=30" providerName="System.Data.SqlClient"/>-->
      <!--<add name="vl360Context" connectionString="Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\360vl.mdf;Integrated Security=True;Connect Timeout=30" providerName="System.Data.SqlClient"/>-->
      <add name="vl360Context" providerName="System.Data.SqlClient" connectionString="data source=.\SQLEXPRESS;Integrated Security=SSPI;AttachDBFilename=|DataDirectory|\vl360.mdf;User Instance=true" />
  </connectionStrings>
  <appSettings>
    <add key="webpages:Version" value="3.0.0.0"/>
    <add key="webpages:Enabled" value="false"/>
    <add key="PreserveLoginUrl" value="true"/>
    <add key="ClientValidationEnabled" value="true"/>
    <add key="UnobtrusiveJavaScriptEnabled" value="true"/>
  </appSettings>
  <!--
    For a description of web.config changes see http://go.microsoft.com/fwlink/?LinkId=235367.

    The following attributes can be set on the <httpRuntime> tag.
      <system.Web>
        <httpRuntime targetFramework="4.5" />
      </system.Web>
  -->
  <system.web>
      <!--Code fix loi-->
      <customErrors mode="Off"/>
      <!--<customErrors mode="RemoteOnly" defaultRedirect="mycustompage.htm"/>-->

    <compilation debug="true" targetFramework="4.5"/>
    <httpRuntime/>
    <authentication mode="None"/>
    <pages controlRenderingCompatibilityVersion="4.0">
      <namespaces>
        <add namespace="System.Web.Helpers"/>
        <add namespace="System.Web.Mvc"/>
        <add namespace="System.Web.Mvc.Ajax"/>
        <add namespace="System.Web.Mvc.Html"/>
        <add namespace="System.Web.Optimization"/>
        <add namespace="System.Web.Routing"/>
        <add namespace="System.Web.WebPages"/>
      </namespaces>
    </pages>
  </system.web>
  <system.webServer>
      <validation validateIntegratedModeConfiguration="false"/>

    <handlers>
        <remove name="WebDAVModule"/>
      <remove name="ExtensionlessUrlHandler-Integrated-4.0"/>
      <remove name="OPTIONSVerbHandler"/>
      <remove name="TRACEVerbHandler"/>
      <add name="ExtensionlessUrlHandler-Integrated-4.0" path="*." verb="*" type="System.Web.Handlers.TransferRequestHandler" preCondition="integratedMode,runtimeVersionv4.0"/>
    </handlers>
  </system.webServer>
  <runtime>
    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
      <dependentAssembly>
        <assemblyIdentity name="EntityFramework" publicKeyToken="b77a5c561934e089"/>
        <bindingRedirect oldVersion="1.0.0.0-5.0.0.0" newVersion="5.0.0.0"/>
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="WebGrease" publicKeyToken="31bf3856ad364e35"/>
        <bindingRedirect oldVersion="0.0.0.0-1.6.5135.21930" newVersion="1.6.5135.21930"/>
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="System.Web.Helpers" publicKeyToken="31bf3856ad364e35"/>
        <bindingRedirect oldVersion="1.0.0.0-3.0.0.0" newVersion="3.0.0.0"/>
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="System.Web.WebPages" publicKeyToken="31bf3856ad364e35"/>
        <bindingRedirect oldVersion="1.0.0.0-3.0.0.0" newVersion="3.0.0.0"/>
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="System.Web.Mvc" publicKeyToken="31bf3856ad364e35"/>
        <bindingRedirect oldVersion="1.0.0.0-5.1.0.0" newVersion="5.1.0.0"/>
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="Microsoft.Data.Edm" publicKeyToken="31bf3856ad364e35" culture="neutral"/>
        <bindingRedirect oldVersion="0.0.0.0-5.6.1.0" newVersion="5.6.1.0"/>
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="Microsoft.Data.OData" publicKeyToken="31bf3856ad364e35" culture="neutral"/>
        <bindingRedirect oldVersion="0.0.0.0-5.6.1.0" newVersion="5.6.1.0"/>
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="System.Spatial" publicKeyToken="31bf3856ad364e35" culture="neutral"/>
        <bindingRedirect oldVersion="0.0.0.0-5.6.1.0" newVersion="5.6.1.0"/>
      </dependentAssembly>
    </assemblyBinding>
  </runtime>
  <entityFramework>
    <defaultConnectionFactory type="System.Data.Entity.Infrastructure.LocalDbConnectionFactory, EntityFramework">
      <parameters>
        <parameter value="v11.0"/>
      </parameters>
    </defaultConnectionFactory>
    <providers>
      <provider invariantName="System.Data.SqlClient" type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer"/>
    </providers>
  </entityFramework>
</configuration>

0 个答案:

没有答案