2011-10-08 53 views
0

我想在OpenRasta中使用/ content/{contentId}的URI模板聲明處理多部分文檔的POST,但它失敗。該配置是如何在OpenRasta中使用form/prefix/{suffix}的URI模板處理多部分POST?

ResourceSpace.Has.ResourcesOfType<Content>().AtUri("/content/{contentId}").HandledBy<ContentHandler>().RenderedByAspx("~/Views/ContentView.aspx").And.AsJsonDataContract(); 

的處理程序方法如下:

public OperationResult Post(string contentId, IEnumerable<IMultipartHttpEntity> entities) {...} 

我使用以下捲曲命令測試

./curl -v -F [email protected]/hello.txt http://localhost:10247/content/id-1 

的POST工作正常,如果我刪除「{ contentId}「,並相應地修改處理程序。

有關如何解決的任何想法?日誌文件如下。謝謝--Roland

4-[2011-10-10 02:27:47Z] Verbose(0) Starts pre-executing the request. 
4-[2011-10-10 02:27:47Z] Verbose(0) Incoming host request for http://localhost:10247/content/id-1 
4-[2011-10-10 02:27:47Z] Verbose(0) Adding communication context data 
4-[2011-10-10 02:27:47Z] Warning(0) Contributor call for BootstrapperContributor had a null Action. 
4-[2011-10-10 02:27:47Z] Start(1) Entering PipelineRunner: Executing contributor HttpMethodOverriderContributor.OverrideHttpVerb 
4-[2011-10-10 02:27:47Z] Stop(1) Exiting PipelineRunner 
4-[2011-10-10 02:27:47Z] Start(1) Entering PipelineRunner: Executing contributor AuthenticationContributor.AuthoriseRequest 
4-[2011-10-10 02:27:47Z] Stop(1) Exiting PipelineRunner 
4-[2011-10-10 02:27:47Z] Start(1) Entering PipelineRunner: Executing contributor UriDecoratorsContributor.ProcessDecorators 
4-[2011-10-10 02:27:47Z] Stop(1) Exiting PipelineRunner 
4-[2011-10-10 02:27:47Z] Start(1) Entering PipelineRunner: Executing contributor ResourceTypeResolverContributor.ResolveResource 
4-[2011-10-10 02:27:51Z] Stop(1) Exiting PipelineRunner 
4-[2011-10-10 02:27:51Z] Verbose(0) Rewrote path. 
4-[2011-10-10 02:27:51Z] Start(1) Entering OpenRastaRewriterHandler: Rewriting to original path 
    4-[2011-10-10 02:27:51Z] Start(1) Entering OpenRastaIntegratedHandler: Request for http://localhost:10247/content/id-1 
     4-[2011-10-10 02:27:51Z] Verbose(0) Incoming host request for http://localhost:10247/content/id-1 
     4-[2011-10-10 02:27:51Z] Verbose(0) Adding communication context data 
     4-[2011-10-10 02:27:51Z] Start(1) Entering PipelineRunner: Executing contributor HandlerResolverContributor.ResolveHandler 
     4-[2011-10-10 02:27:51Z] Stop(1) Exiting PipelineRunner 
     4-[2011-10-10 02:27:51Z] Start(1) Entering PipelineRunner: Executing contributor OperationCreatorContributor.CreateOperations 
      4-[2011-10-10 02:27:51Z] Verbose(0) Created operation named Get with signature ContentHandler::Get(String contentId) 
      4-[2011-10-10 02:27:51Z] Verbose(0) Created operation named Post with signature ContentHandler::Post(String contentId, IEnumerable`1 entities) 
     4-[2011-10-10 02:27:51Z] Stop(1) Exiting PipelineRunner 
     4-[2011-10-10 02:27:51Z] Start(1) Entering PipelineRunner: Executing contributor OperationFilterContributor.ProcessOperations 
      4-[2011-10-10 02:27:51Z] Verbose(0) Found 1 operation(s) with a matching name. 
      4-[2011-10-10 02:27:51Z] Verbose(0) Found 0 operation(s) with matching [HttpOperation] attribute. 
      4-[2011-10-10 02:27:51Z] Verbose(0) No resource or no uri name. Not filtering. 
     4-[2011-10-10 02:27:51Z] Stop(1) Exiting PipelineRunner 
     4-[2011-10-10 02:27:51Z] Start(1) Entering PipelineRunner: Executing contributor OperationCodecSelectorContributor.ProcessOperations 
      4-[2011-10-10 02:27:51Z] Information(0) Operation ContentHandler::Post(String contentId, IEnumerable`1 entities) selected with 2 required members and 0 optional members, with codec MultipartFormDataKeyedValuesCodec with score 1.5. 
     4-[2011-10-10 02:27:51Z] Stop(1) Exiting PipelineRunner 
     4-[2011-10-10 02:27:51Z] Start(1) Entering PipelineRunner: Executing contributor OperationHydratorContributor.ProcessOperations 
      4-[2011-10-10 02:27:51Z] Information(0) Operation ContentHandler::Post(String contentId, IEnumerable`1 entities) was selected with a codec score of 1.5 
      4-[2011-10-10 02:27:51Z] Information(0) Loaded codec OpenRasta.Codecs.MultipartFormDataKeyedValuesCodec 
      4-[2011-10-10 02:27:51Z] Information(0) Codec supports IKeyedValuesMediaTypeReader. Processing parameters. 
      4-[2011-10-10 02:27:51Z] Verbose(0) Seeking to next available part 
      4-[2011-10-10 02:27:51Z] Verbose(0) Skip the preamble. AtPreamble was True. 
      4-[2011-10-10 02:27:51Z] Verbose(0) not null 
      4-[2011-10-10 02:27:51Z] Verbose(0) Preamble found: True of size 0 
      4-[2011-10-10 02:27:51Z] Verbose(0) not null 
      4-[2011-10-10 02:27:51Z] Verbose(0) not null 
      4-[2011-10-10 02:27:51Z] Verbose(0) not null 
      4-[2011-10-10 02:27:51Z] Verbose(0) Skip the preamble. AtPreamble was False. 
      4-[2011-10-10 02:27:51Z] Verbose(0) Preamble found: False of size 0 
      4-[2011-10-10 02:27:51Z] Verbose(0) not null 
      4-[2011-10-10 02:27:51Z] Verbose(0) not null 
      4-[2011-10-10 02:27:51Z] Verbose(0) Seeking to next available part 
      4-[2011-10-10 02:27:51Z] Verbose(0) not null 
      4-[2011-10-10 02:27:51Z] Verbose(0) not null 
      4-[2011-10-10 02:27:51Z] Verbose(0) Key myPartName was not successfully assigned. 
      4-[2011-10-10 02:27:51Z] Verbose(0) Key myPartName was not successfully assigned. 
     4-[2011-10-10 02:27:51Z] Stop(1) Exiting PipelineRunner 
     4-[2011-10-10 02:27:51Z] Start(1) Entering PipelineRunner: Executing contributor OperationInterceptorContributor.WrapOperations 
     4-[2011-10-10 02:27:51Z] Stop(1) Exiting PipelineRunner 
     4-[2011-10-10 02:27:51Z] Start(1) Entering PipelineRunner: Executing contributor OperationInvokerContributor.ExecuteOperations 
      4-[2011-10-10 02:27:51Z] Verbose(0) Ignoring constructor, following dependencies didn't have a registration:OpenRasta.OperationModel.Interceptors.IOperationInterceptor[] 
A first chance exception of type 'System.InvalidOperationException' occurred in OpenRasta.DLL 
      4-[2011-10-10 02:27:52Z] Error(0) An error of type System.InvalidOperationException has been thrown 
      4-[2011-10-10 02:27:52Z] Error(0) System.InvalidOperationException: The operation is not ready for invocation. 
      4-[2011-10-10 02:27:52Z] Error(0) at OpenRasta.OperationModel.MethodBased.MethodBasedOperation.Invoke() in C:\Users\hochmuth\Repositories\openrasta-core\src\OpenRasta\OperationModel\MethodBased\MethodBasedOperation.cs:line 56 
      4-[2011-10-10 02:27:52Z] Error(0) at OpenRasta.OperationModel.Interceptors.OperationWithInterceptors.<Invoke>b__0() in C:\Users\hochmuth\Repositories\openrasta-core\src\OpenRasta\OperationModel\Interceptors\OperationWithInterceptors.cs:line 47 
      4-[2011-10-10 02:27:52Z] Error(0) at OpenRasta.OperationModel.Interceptors.OperationWithInterceptors.Invoke() in C:\Users\hochmuth\Repositories\openrasta-core\src\OpenRasta\OperationModel\Interceptors\OperationWithInterceptors.cs:line 52 
      4-[2011-10-10 02:27:52Z] Error(0) at OpenRasta.OperationModel.OperationExecutor.Execute(IEnumerable`1 operations) in C:\Users\hochmuth\Repositories\openrasta-core\src\OpenRasta\OperationModel\OperationExecutor.cs:line 14 
      4-[2011-10-10 02:27:52Z] Error(0) at OpenRasta.Pipeline.Contributors.OperationInvokerContributor.ExecuteOperations(ICommunicationContext context) in C:\Users\hochmuth\Repositories\openrasta-core\src\OpenRasta\Pipeline\Contributors\OperationInvokerContributor.cs:line 29 
      4-[2011-10-10 02:27:52Z] Error(0) at OpenRasta.Pipeline.PipelineRunner.ExecuteContributor(ICommunicationContext context, ContributorCall call) in C:\Users\hochmuth\Repositories\openrasta-core\src\OpenRasta\Pipeline\PipelineRunner.cs:line 192 
     4-[2011-10-10 02:27:52Z] Stop(1) Exiting PipelineRunner 
     4-[2011-10-10 02:27:52Z] Error(0) Aborting the pipeline and rendering the errors. 
     4-[2011-10-10 02:27:52Z] Error(0) An error has occurred and the processing of the request has stopped. 

Exception: 
System.InvalidOperationException: The operation is not ready for invocation. 
    at OpenRasta.OperationModel.MethodBased.MethodBasedOperation.Invoke() in C:\Users\hochmuth\Repositories\openrasta-core\src\OpenRasta\OperationModel\MethodBased\MethodBasedOperation.cs:line 56 
    at OpenRasta.OperationModel.Interceptors.OperationWithInterceptors.<Invoke>b__0() in C:\Users\hochmuth\Repositories\openrasta-core\src\OpenRasta\OperationModel\Interceptors\OperationWithInterceptors.cs:line 47 
    at OpenRasta.OperationModel.Interceptors.OperationWithInterceptors.Invoke() in C:\Users\hochmuth\Repositories\openrasta-core\src\OpenRasta\OperationModel\Interceptors\OperationWithInterceptors.cs:line 52 
    at OpenRasta.OperationModel.OperationExecutor.Execute(IEnumerable`1 operations) in C:\Users\hochmuth\Repositories\openrasta-core\src\OpenRasta\OperationModel\OperationExecutor.cs:line 14 
    at OpenRasta.Pipeline.Contributors.OperationInvokerContributor.ExecuteOperations(ICommunicationContext context) in C:\Users\hochmuth\Repositories\openrasta-core\src\OpenRasta\Pipeline\Contributors\OperationInvokerContributor.cs:line 29 
    at OpenRasta.Pipeline.PipelineRunner.ExecuteContributor(ICommunicationContext context, ContributorCall call) in C:\Users\hochmuth\Repositories\openrasta-core\src\OpenRasta\Pipeline\PipelineRunner.cs:line 192 
     4-[2011-10-10 02:27:52Z] Verbose(0) Pipeline is in RenderNow mode. 
     4-[2011-10-10 02:27:52Z] Start(1) Entering PipelineRunner: Executing contributor OperationResultInvokerContributor.RunOperationResult 
      4-[2011-10-10 02:27:52Z] Information(0) Executing OperationResult OperationResult: type=InternalServerError, statusCode=500. 
     4-[2011-10-10 02:27:52Z] Stop(1) Exiting PipelineRunner 
     4-[2011-10-10 02:27:52Z] Start(1) Entering PipelineRunner: Executing contributor ResponseEntityCodecResolverContributor.FindResponseCodec 
      4-[2011-10-10 02:27:52Z] Information(0) Selected codec HtmlErrorCodec out of 2 codecs for entity of type ServerErrorList and negotiated media type text/html; q=0.5. 
     4-[2011-10-10 02:27:52Z] Stop(1) Exiting PipelineRunner 
     4-[2011-10-10 02:27:52Z] Start(1) Entering PipelineRunner: Executing contributor AuthenticationChallengerContributor.ChallengeIfUnauthorized 
     4-[2011-10-10 02:27:52Z] Stop(1) Exiting PipelineRunner 
     4-[2011-10-10 02:27:52Z] Start(1) Entering PipelineRunner: Executing contributor ResponseEntityWriterContributor.WriteResponse 
      4-[2011-10-10 02:27:52Z] Verbose(0) Codec HtmlErrorCodec selected. 
      4-[2011-10-10 02:27:52Z] Start(1) Entering ResponseEntityWriterContributor: Generating response entity. 
       4-[2011-10-10 02:27:52Z] Verbose(0) Setting Content-Length to 2159 
      4-[2011-10-10 02:27:52Z] Stop(1) Exiting ResponseEntityWriterContributor 
      4-[2011-10-10 02:27:52Z] Verbose(0) Writing http headers. 
      4-[2011-10-10 02:27:52Z] Verbose(0) Writing http header Content-Length:2159 
      4-[2011-10-10 02:27:52Z] Verbose(0) Writing http header Content-Type:text/html 
     4-[2011-10-10 02:27:52Z] Stop(1) Exiting PipelineRunner 
     4-[2011-10-10 02:27:52Z] Information(0) Pipeline finished. 
    4-[2011-10-10 02:27:52Z] Stop(1) Exiting OpenRastaIntegratedHandler 
4-[2011-10-10 02:27:52Z] Stop(1) Exiting OpenRastaRewriterHandler 
4-[2011-10-10 02:27:52Z] Verbose(0) Request finished. 
The thread '<No Name>' (0x1f68) has exited with code 0 (0x0). 
+0

如果您將調試日誌添加到問題中,我們可能有助於瞭解發生了什麼。 – SerialSeb

+0

嗨Serialseb,我將調試日誌添加到原來的問題。謝謝 - 羅蘭 – user985004

回答

1

從日誌中,您可以看到multipart編解碼器正在用於鍵/值處理模式。在這種模式下,多部分的內容正在被解析,而不是分配IEnumerable,這當然是該編解碼器的問題。

我添加了一個錯誤,在https://github.com/openrasta/openrasta-core/issues/32

來解決這個問題,在此期間,你可以讓多編解碼器反序列化的內容根據需要(您可以通過簡單的映射DTO或輸入參數使用表單實體的名稱,OpenWrap將允許您將表單數據分配到標準屬性,以及將文件分配到流中)。

或者,根據您的需要,您可以通過覆蓋依賴註冊器來取消註冊鍵/值mutlipart編解碼器,並讓對象註冊工作正常進行。

+0

謝謝Serialseb!我很快嘗試了第二種方法,覆蓋了依賴註冊服務器,並且工作。這對我們來說似乎是一個很好的解決方法。期待實際的修復。感謝您的快速響應! --Roland – user985004

相關問題