Openrasta posting to resource at the base uri

772 views Asked by At

I have a site in iis7 hosting several openrasta applications as virtual directories. One of these openrasta application hosts a single resource, so I want it to run in the root of that virtual directory. I am able to GET the resource succesfully but am unable to POST the resource. When POSTing I get a 405 error.

Locally it looks like:

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

I want to add another app, but as this app will only contain 1 resource I want to access it through the base uri of the app. I.e.

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

I am able to GET resource5 but am unable to POST to it using the below configuration.

It should not match the template "/{id}" as I do not include an ID when posting.

My configuration is as follows:

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

And my handler code is:

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());
    }
}

Debug log as follows

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.

Anyone out there able to help me with this?

Cheers

Dave

2

There are 2 answers

3
SerialSeb On

Without log, I'd only provide one simple potential answer. Check what other modules you have defined in IIS and remove (or reorder) the ones that would take a POST to / (such as default documents). A lot of those modules will greedily assume they own the request, causing compat hell.

2
SerialSeb On

Posting another answer as the problem is different.

The log says you attempt to do something on /Thing, which matches the template /{id}. That template is then mapped in your method to an id of type int. Thing cannot be converted to int, hence the failure.

Are you saying that your application is in a virtual directory in /Thing? If that's the case, either you need to mark the virtual directory as an application, or you need to map the URI as /Thing/{id} and /Thing/ instead.