这是OpenAccessBaseAPIController.cs
public abstract partial class OpenAccessBaseAPIController<TEntity,TContext> : ODataController where TContext : OpenAccessContext,new(){ protected IOpenAccessBaseRepository<TEntity,TContext> repository; public virtual Iqueryable<TEntity> Get() { var allEntitIEs = repository.GetAll(); return allEntitIEs; } /// <summary> /// Creates a new entity based on the provIDed data /// </summary> /// <param name="entity">The new entity to be created</param> /// <returns>http Status: /// - Accepted when operation is successful or /// - MethodNotAllowed if the operation is Disabled for this entity or /// - BadRequest if the provIDed entity is NulL</returns> public virtual httpResponseMessage Post(TEntity entity) { if (entity == null) throw new httpResponseException(httpStatusCode.BadRequest); //Todo: should we check if the incomming entity is not an existing one? TEntity newEntity = repository.AddNew(entity); var response = CreateResponse(httpStatusCode.Accepted,newEntity); return response; } protected abstract httpResponseMessage CreateResponse(httpStatusCode httpStatusCode,TEntity entityToEmbed);}
这是默认的NumberSequencesController.cs
public partial class NumberSequencesController : OpenAccessBaseAPIController<MyERP.DataAccess.NumberSequence,MyERP.DataAccess.EntitIEsModel>{ /// <summary> /// Constructor used by the Web API infrastructure. /// </summary> public NumberSequencesController() { this.repository = new NumberSequenceRepository(); } /// <summary> /// Dependency Injection ready constructor. /// Usable also for unit testing. /// </summary> /// <remarks>Web API Infrastructure will ALWAYS use the default constructor!</remarks> /// <param name="repository">Repository instance of the specific type</param> public NumberSequencesController(IOpenAccessBaseRepository<MyERP.DataAccess.NumberSequence,MyERP.DataAccess.EntitIEsModel> repository) { this.repository = repository; }...}
这是我的工具NumberSequencesController.partial.cs
public partial class NumberSequencesController { public SingleResult<NumberSequence> GetNumberSequence([FromODataUri] GuID key) { return SingleResult.Create(repository.GetAll().Where(c => c.ID == key).Asqueryable()); } /// <summary> /// Updates single entity. /// </summary> /// <remarks>Replaces the whole existing entity with the provIDed one</remarks> /// <param name="ID">ID of the entity to update</param> /// <param name="entity">Entity with the new updated values</param> /// <returns>httpStatusCode.BadRequest if ID parameter does not match the ID value of the entity,/// or httpStatusCode.NoContent if the operation was successful</returns> public httpResponseMessage PutNumberSequence([FromODataUri] GuID ID,MyERP.DataAccess.NumberSequence entity) { if (entity == null || ID != entity.ID) throw new httpResponseException(httpStatusCode.BadRequest); repository.Update(entity); return Request.CreateResponse(httpStatusCode.NoContent); }}
我的ODATA网址:
http://localhost//MyERP.Web/odata/NumberSequences(guID'f640510c-365e-434f-9377-0118f22319fc')
工作得很好.但是,当我PUT更新ODATA我有错误没有找到匹配请求的http资源.这是FIDder数据
PUT /MyERP.Web/odata/NumberSequences(guID'f640510c-365e-434f-9377-0118f22319fc') http/1.1Host: localhostConnection: keep-aliveContent-Length: 1855Cache-Control: no-cacheUser-Agent: Mozilla/5.0 (windows NT 6.3; WOW64) AppleWebKit/537.36 (KHTML,like Gecko) Chrome/35.0.1916.114 Safari/537.36Origin: Chrome-extension://fdmmgilgnpjigdojojpjoooIDkmcomcmAuthorization: Basic REVNTzpXQVpOODFQQy9RY0NsMmRDc01ZZGp3PT0=Content-Type: text/plain;charset=UTF-8Accept: */*Accept-EnCoding: gzip,deflate,sdchAccept-Language: en-US,en;q=0.8,vi;q=0.6
身体
<?xml version="1.0" enCoding="utf-8"?><entry xmlns="http://www.w3.org/2005/Atom" xmlns:d="http://schemas.microsoft.com/ado/2007/08/dataservices" xmlns:m="http://schemas.microsoft.com/ado/2007/08/dataservices/Metadata"> <ID>http://localhost/MyERP.Web/odata/NumberSequences(guID'f640510c-365e-434f-9377-0118f22319fc')</ID> <category term="MyERP.DataAccess.NumberSequence" scheme="http://schemas.microsoft.com/ado/2007/08/dataservices/scheme" /> <Title /> <updated>2014-05-28T07:50:39Z</updated> <author><name /></author> <content type="application/xml"> <m:propertIEs> <d:ClIEntID m:type="Edm.GuID">28cc612c-807d-458d-91e7-f759080b0e40</d:ClIEntID> <d:Code>GL002</d:Code> <d:CurrentNo m:type="Edm.Int32">1</d:CurrentNo> <d:EndingNo m:type="Edm.Int32">9999</d:EndingNo> <d:FormatNo>GL000</d:FormatNo> <d:ID m:type="Edm.GuID">f640510c-365e-434f-9377-0118f22319fc</d:ID> <d:IsDefault m:type="Edm.Boolean">false</d:IsDefault> <d:Manual m:type="Edm.Boolean">false</d:Manual> <d:name>Chung tu tong hop</d:name> <d:NoSeqname>seq_no_serIEs_f640510c_365e_434f_9377_0118f22319fc</d:NoSeqname> <d:OrganizationID m:type="Edm.GuID">4336fecf-8c21-4531-afe6-76d34603ea34</d:OrganizationID> <d:RecCreated m:type="Edm.DateTime">2014-05-11T00:28:57.754334</d:RecCreated> <d:RecCreatedBy m:type="Edm.GuID">5e6af2aa-e21a-4afd-815e-0cc3dbefa08a</d:RecCreatedBy> <d:RecModifIEd m:type="Edm.DateTime">2014-05-11T00:28:57.754334</d:RecModifIEd> <d:RecModifIEdBy m:type="Edm.GuID">5e6af2aa-e21a-4afd-815e-0cc3dbefa08a</d:RecModifIEdBy> <d:StartingNo m:type="Edm.Int32">1</d:StartingNo> <d:Status m:type="Edm.Int16">1</d:Status> <d:StatusType>Active</d:StatusType> <d:Version m:type="Edm.Int64">1</d:Version> </m:propertIEs> </content>
它有错误:
{ "odata.error":{ "code":"","message":{ "lang":"en-US","value":"No http resource was found that matches the request URI 'http://localhost/MyERP.Web/odata/NumberSequences(guID'f640510c-365e-434f-9377-0118f22319fc')'." },"innererror":{ "message":"No action was found on the controller 'NumberSequences' that matches the request.","type":"","stacktrace":"" } }}解决方法 请将PutNumberSequence的“ID”参数重命名为“key”.
从
public httpResponseMessage PutNumberSequence( [FromODataUri] GuID ID,MyERP.DataAccess.NumberSequence entity)
至
public httpResponseMessage PutNumberSequence( [FromODataUri] GuID key,MyERP.DataAccess.NumberSequence entity)总结
以上是内存溢出为你收集整理的WEB API ODATA错误“找不到与请求匹配的HTTP资源”全部内容,希望文章能够帮你解决WEB API ODATA错误“找不到与请求匹配的HTTP资源”所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)