不允许使用AngularJS BreezeJS-405方法
我已经创建了一个OData服务,但是当错误查询由BreezeJS执行时。 这是我查询的结果不允许使用AngularJS BreezeJS-405方法,angularjs,breeze,Angularjs,Breeze,我已经创建了一个OData服务,但是当错误查询由BreezeJS执行时。 这是我查询的结果 http://115.78.161.4:96/odata/ShArticles Breeze配置:Breeze.Config.initializedapterninstance('dataService','webApiOData',true) 代码查询 function getShArticles(forceRefresh) { var count;
http://115.78.161.4:96/odata/ShArticles
Breeze配置:Breeze.Config.initializedapterninstance('dataService','webApiOData',true)
代码查询
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));
}
}
公共类ShArticlesController:ODataController
{
私有静态ODataValidationSettings _validationSettings=新ODataValidationSettings();
vl360Context db=新的vl360Context();
//获取odata/ShArticles
[可查询]
公共IQueryable GetShArticles()
{
返回db.ShArticles;
}
//获取odata/ShArticles(5)
[可查询]
公共SingleResult GetShArticle([FromODataUri]int键)
{
返回SingleResult.Create(db.ShArticles.Where(x=>x.ArticleID==key));
}
}
真诚的感谢任何意见的帮助
代码寄存器生成器:
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();
公共静态无效寄存器(HttpConfiguration配置)
{
config.maphttpAttribute路由();
config.Routes.MapODataRoute(
routeName:“odata”,
routePrefix:“odata”,
模型:EdmBuilder.GetEdm(),
batchHandler:新的DefaultODataBatchHandler(GlobalConfiguration.DefaultServer)
);
config.Routes.MapHttpRoute(
名称:“DefaultApi”,
routeTemplate:“api/{controller}/{id}”,
默认值:新建{id=RouteParameter.Optional}
);
//取消注释以下代码行,以启用对具有IQueryable或IQueryable返回类型的操作的查询支持。
//要避免处理意外或恶意查询,请使用QueryableAttribute上的验证设置验证传入的查询。
//有关更多信息,请访问http://go.microsoft.com/fwlink/?LinkId=279712.
config.EnableQuerySupport();
网络配置:
<?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>
除非您向我们展示如何在服务器上配置OData,否则无法提供帮助。您是否正在使用ODataConventionBuilder
?EdmBuilder
?您描述的错误通常是服务器配置的结果,而不是BreezeJS。当您使用浏览器或Fiddler点击OData端点时会发生什么?我已更新了代码寄存器EdmBuiderI从其他客户端访问OdataService,如何配置?需要更多编辑。vl360Context
如何公开ShaArticle
?您可以丢弃web.config和查询,因为它们无关紧要。如果(我打赌)当您输入http://115.78.161.4:96/odata/ShArticles
进入浏览器地址栏,您遇到的是服务器配置问题,而不是BreezeJS问题。请确认。查看:
<?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>