gpt4 book ai didi

odata - WEB API ODATA 错误 "No HTTP resource was found that matches the request"

转载 作者:行者123 更新时间:2023-12-04 17:48:44 24 4
gpt4 key购买 nike

我正在将 WEB API ODATA 与 Telerik OpenAccess 一起使用

这是 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.1
Host: localhost
Connection: keep-alive
Content-Length: 1855
Cache-Control: no-cache
User-Agent: Mozilla/5.0 (Windows NT 6.3; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/35.0.1916.114 Safari/537.36
Origin: chrome-extension://fdmmgilgnpjigdojojpjoooidkmcomcm
Authorization: Basic REVNTzpXQVpOODFQQy9RY0NsMmRDc01ZZGp3PT0=
Content-Type: text/plain;charset=UTF-8
Accept: */*
Accept-Encoding: gzip,deflate,sdch
Accept-Language: en-US,en;q=0.8,vi;q=0.6

body
<?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)

关于odata - WEB API ODATA 错误 "No HTTP resource was found that matches the request",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23910710/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com