Openrasta发布到基础uri的资源

时间:2011-02-25 10:40:59

标签: openrasta

我在iis7中有一个站点,将几个openrasta应用程序托管为虚拟目录。其中一个openrasta应用程序托管一个资源,所以我希望它在该虚拟目录的根目录中运行。我能够成功获取资源但无法发布资源。 POST时我得到405错误。

在本地看起来像:

http://localhost/OpenRastaApp1/Resource1
http://localhost/OpenRastaApp1/Resource2
http://localhost/OpenRastaApp2/Resource3
http://localhost/OpenRastaApp2/Resource4

我想添加另一个应用,但由于此应用只包含1个资源,我想通过应用的基础uri访问它。即。

http://localhost/OpenRastaApp3 not http://localhost/OpenRastaApp3/Resource5

我能够获取资源5,但无法使用以下配置对其进行POST。

它不应与模板“/ {id}”匹配,因为我在发布时不包含ID。

我的配置如下:

ResourceSpace.Has
    .ResourcesOfType<ThingResource>()
    .AtUri("/").And
    .AtUri("/{id}")
    .HandledBy<ThingHandler>()
    .AsJsonDataContract();

我的处理程序代码是:

public class ThingHandler
{
    [HttpOperation(HttpMethod.POST)]
    public OperationResult Post(ThingResource thingResource)
    {
        var thing = thingResource.ToThingEntity();
        thing = _thingService.Make(thing);
        return new OperationResult.OK(thing.ToThingResource());
    }

    [HttpOperation(HttpMethod.GET)]
    public OperationResult Get(int id)
    {
        var thing = _thingService.Get(id);
        return new OperationResult.OK(thing.ToThingResource());
    }
}

调试日志如下

13-[2011-03-01 10:38:59Z] Verbose(0) Incoming host request for http://api.local.site.com/Thing
13-[2011-03-01 10:38:59Z] Verbose(0) Adding communication context data
13-[2011-03-01 10:38:59Z] Warning(0) Contributor call for BootstrapperContributor had a null Action.
13-[2011-03-01 10:38:59Z] Start(1) Entering PipelineRunner: Executing contributor ExceptionHandlerContributor.LogException
13-[2011-03-01 10:38:59Z] Stop(1) Exiting PipelineRunner
13-[2011-03-01 10:38:59Z] Start(1) Entering PipelineRunner: Executing contributor HttpMethodOverriderContributor.OverrideHttpVerb
13-[2011-03-01 10:38:59Z] Stop(1) Exiting PipelineRunner
13-[2011-03-01 10:38:59Z] Start(1) Entering PipelineRunner: Executing contributor DigestAuthorizerContributor.ReadCredentials
13-[2011-03-01 10:38:59Z] Stop(1) Exiting PipelineRunner
13-[2011-03-01 10:38:59Z] Start(1) Entering PipelineRunner: Executing contributor UriDecoratorsContributor.ProcessDecorators
13-[2011-03-01 10:38:59Z] Stop(1) Exiting PipelineRunner
13-[2011-03-01 10:38:59Z] Start(1) Entering PipelineRunner: Executing contributor ResourceTypeResolverContributor.ResolveResource
13-[2011-03-01 10:38:59Z] Stop(1) Exiting PipelineRunner
13-[2011-03-01 10:38:59Z] Start(1) Entering PipelineRunner: Executing contributor HandlerResolverContributor.ResolveHandler
13-[2011-03-01 10:38:59Z] Stop(1) Exiting PipelineRunner
13-[2011-03-01 10:38:59Z] Start(1) Entering PipelineRunner: Executing contributor OperationCreatorContributor.CreateOperations
    13-[2011-03-01 10:38:59Z] Verbose(0) Created operation named Post with signature ThingHandler::Post(ThingResource ThingResource)
    13-[2011-03-01 10:38:59Z] Verbose(0) Created operation named Get with signature ThingHandler::Get(Int32 id)
    13-[2011-03-01 10:38:59Z] Verbose(0) Created operation named Amend with signature ThingHandler::Amend(ThingResource ThingResource)
    13-[2011-03-01 10:38:59Z] Verbose(0) Created operation named Cancel with signature ThingHandler::Cancel(Int32 id)
13-[2011-03-01 10:38:59Z] Stop(1) Exiting PipelineRunner
13-[2011-03-01 10:38:59Z] Start(1) Entering PipelineRunner: Executing contributor OperationFilterContributor.ProcessOperations
    13-[2011-03-01 10:38:59Z] Verbose(0) Found 1 operation(s) with a matching name.
    13-[2011-03-01 10:38:59Z] Verbose(0) Found 1 operation(s) with matching [HttpOperation] attribute.
    13-[2011-03-01 10:38:59Z] Verbose(0) No resource or no uri name. Not filtering.
A first chance exception of type 'System.FormatException' occurred in mscorlib.dll
A first chance exception of type 'System.FormatException' occurred in mscorlib.dll
A first chance exception of type 'System.Exception' occurred in System.dll
A first chance exception of type 'System.NotSupportedException' occurred in OpenRasta.DLL
A first chance exception of type 'System.FormatException' occurred in mscorlib.dll
A first chance exception of type 'System.FormatException' occurred in mscorlib.dll
A first chance exception of type 'System.Exception' occurred in System.dll
A first chance exception of type 'System.NotSupportedException' occurred in OpenRasta.DLL
    13-[2011-03-01 10:38:59Z] Error(0) None of the operations had members that could be matches against the uri parameters:
id=Thing;

13-[2011-03-01 10:38:59Z] Stop(1) Exiting PipelineRunner
13-[2011-03-01 10:38:59Z] Verbose(0) Pipeline is in RenderNow mode.
13-[2011-03-01 10:38:59Z] Start(1) Entering PipelineRunner: Executing contributor OperationResultInvokerContributor.RunOperationResult
    13-[2011-03-01 10:38:59Z] Information(0) Executing OperationResult OperationResult: type=MethodNotAllowed, statusCode=405.
13-[2011-03-01 10:38:59Z] Stop(1) Exiting PipelineRunner
13-[2011-03-01 10:38:59Z] Start(1) Entering PipelineRunner: Executing contributor ResponseEntityCodecResolverContributor.FindResponseCodec
    13-[2011-03-01 10:38:59Z] Information(0) No response codec was searched for. The response entity is null or a response codec is already set.
13-[2011-03-01 10:38:59Z] Stop(1) Exiting PipelineRunner
13-[2011-03-01 10:38:59Z] Start(1) Entering PipelineRunner: Executing contributor DigestAuthorizerContributor.WriteCredentialRequest
13-[2011-03-01 10:38:59Z] Stop(1) Exiting PipelineRunner
13-[2011-03-01 10:38:59Z] Start(1) Entering PipelineRunner: Executing contributor ResponseEntityWriterContributor.WriteResponse
    13-[2011-03-01 10:38:59Z] Verbose(0) There was no response entity, not rendering.
    13-[2011-03-01 10:38:59Z] Verbose(0) Writing http headers.
13-[2011-03-01 10:38:59Z] Stop(1) Exiting PipelineRunner
13-[2011-03-01 10:38:59Z] Information(0) Pipeline finished.

那里的任何人都可以帮我这个吗?

干杯

戴夫

2 个答案:

答案 0 :(得分:0)

没有日志,我只提供一个简单的潜在答案。检查您在IIS中定义的其他模块,并删除(或重新排序)将对POST进行POST的模块(例如默认文档)。很多这些模块都会贪婪地假设他们拥有这个请求,导致了地狱。

答案 1 :(得分:0)

发布另一个答案,因为问题不同。

日志说你试图对/ Thing做一些事情,它与模板/ {id}相匹配。然后,该模板在您的方法中映射到int类型的id。事情无法转换为int,因此失败。

您是说您的应用程序位于/ Thing中的虚拟目录中?如果是这种情况,您需要将虚拟目录标记为应用程序,或者需要将URI映射为/ Thing / {id}和/ Thing /。