ASP .NET Web API を使用して OData Web サービスをセットアップする際に問題があります。そのサービスをデータ ソースとして Lightswitch に提供する必要があります。Get リクエストは正常に機能しますが、POST を試すと、ここで行き詰まりました。
エラー
Lightswitch で次のエラーが表示されます。
{"メッセージ":"バッチ リクエストには、メディア タイプとして 'multipart/mixed' が必要です。"}
追加/編集コマンドを呼び出すとき。
Lightswitch には $batch エンドポイントが必要なので、それらをサポートする最新の RC バージョンの Web API をインストールしました。また、バッチ エンドポイントの構成を開始する前に、 http ://www.asp.net/web-api/overview/odata-support-in-aspnet-web-api のチュートリアルに従いました。
次に、このチュートリアルに従ってバッチ エンドポイントをセットアップしました: https://aspnetwebstack.codeplex.com/wikipage?title=Web%20API%20Request%20Batching
私はこの投稿を見直しました:作成方法/バッチ エンドポイントが asp.net OData Web サービス用であり、プロジェクトを DefaultODataBatchHandler でコンパイルすることができました。それでも、バッチ要求/応答を行うことはできません。
私が試したシナリオの詳細:
リクエスト/レスポンス - Fiddler からのデータ
Lightswich クライアントから送信されたリクエスト:
POST http://localhost:3352/ContainerData.svc/$batch HTTP/1.1
DataServiceVersion: 1.0
Accept: multipart/mixed
Content-Type: multipart/mixed;boundary=batch_730c-bd5b-40de
MaxDataServiceVersion: 3.0
Referer: http://localhost:3352/HTMLClient/
Accept-Language: en-GB
Accept-Encoding: gzip, deflate
User-Agent: Mozilla/5.0 (compatible; MSIE 10.0; Windows NT 6.1; Trident/6.0)
Connection: Keep-Alive
Content-Length: 535
DNT: 1
Host: localhost:3352
Pragma: no-cache
--batch_730c-bd5b-40de
Content-Type: multipart/mixed; boundary=changeset_2952-4c78-0ea1
--changeset_2952-4c78-0ea1
Content-Type: application/http
Content-Transfer-Encoding: binary
POST ServiceProviders HTTP/1.1
Content-ID: 0
Accept: application/atomsvc+xml;q=0.8, application/json;odata=verbose;q=0.5, */*;q=0.1
DataServiceVersion: 1.0
Content-Type: application/json
MaxDataServiceVersion: 3.0
{"ID":2,"CategoryID":1,"Name":"fdfdrer","Description":"fefdf"}
--changeset_2952-4c78-0ea1--
--batch_730c-bd5b-40de--
Web API の応答:
HTTP/1.1 202 Accepted
Cache-Control: no-cache
Content-Length: 2886
Content-Type: multipart/mixed; boundary=batchresponse_663f69c3-6315-447b-b179-00bf407c3b09
Server: Microsoft-IIS/8.0
X-Content-Type-Options: nosniff
DataServiceVersion: 1.0;
X-AspNet-Version: 4.0.30319
X-SourceFiles: =?UTF-8?B?QzpcVXNlcnNcdmd0MWcxMlxEb2N1bWVudHNcVmlzdWFsIFN0dWRpbyAyMDEyXFByb2plY3RzXE1ha2VZb3VyQ2hvaWNlXE1ha2VZb3VyQ2hvaWNlVUlcTWFrZVlvdXJDaG9pY2VVSVxCaW5cRGVidWdcQ29udGFpbmVyRGF0YS5zdmNcJGJhdGNo?=
X-Powered-By: ASP.NET
Date: Fri, 05 Jul 2013 11:01:49 GMT
--batchresponse_663f69c3-6315-447b-b179-00bf407c3b09
Content-Type: multipart/mixed; boundary=changesetresponse_d1537003-f0cd-4fe2-b4b1-2f562b3179d0
--changesetresponse_d1537003-f0cd-4fe2-b4b1-2f562b3179d0
Content-Type: application/http
Content-Transfer-Encoding: binary
HTTP/1.1 500 Internal Server Error
Content-ID: 0
X-Content-Type-Options: nosniff
Cache-Control: no-cache
DataServiceVersion: 1.0;
Content-Type: application/json;odata=verbose;charset=utf-8
{"error":{"code":"1","message":{"lang":"en-GB","value":"<?xml version=\"1.0\" encoding=\"utf-16\"?><ExceptionInfo><Message>One or more of the changes failed to save. To ensure consistency, refresh and re-apply your changes.\r\nInner exception message:\r\nAn error occurred while processing this request.\r\nInner exception message:\r\n{\"Message\":\"The batch request must have 'multipart/mixed' as the media type.\"}</Message><StackTrace>
at Microsoft.LightSwitch.ServerGenerated.Implementation.DataProvider.AstoriaDataServiceDataProvider.<>c__DisplayClass1.<SubmitCore>b__0()\r\n
at Microsoft.LightSwitch.ServerGenerated.Implementation.DataProvider.AstoriaDataServiceDataProvider.InvokeAstoriaOperation(DataServiceContext context, Action astoriaOperation)\r\n
at Microsoft.LightSwitch.ServerGenerated.Implementation.DataProvider.AstoriaDataServiceDataProvider.SubmitCore(IEnumerable`1 changes)\r\n
at Microsoft.LightSwitch.ServerGenerated.Implementation.DataProvider.DataProvider.Submit(IEnumerable`1 changes)\r\n
at Microsoft.LightSwitch.ServerGenerated.Implementation.DataServiceImplementation`1.PerformPersistCore(IEnumerable`1 eventsChangeSetItems)\r\n
at Microsoft.LightSwitch.ServerGenerated.Implementation.DataServiceImplementation`1.<>c__DisplayClass46.<PerformPersist>b__45()\r\n
at Microsoft.LightSwitch.Threading.DualDispatcherObject.Mutate(IDispatcher logicDispatcher, MutatorHost host, Action mutator)\r\n
at Microsoft.LightSwitch.ServerGenerated.Implementation.DataServiceImplementation`1.PerformPersist(IEnumerable`1 eventsChangeSetItems)\r\n
at Microsoft.LightSwitch.ServerGenerated.Implementation.DataServiceImplementation`1.Microsoft.LightSwitch.ServerGenerated.Implementation.IServerDataServiceImplementationCore.Submit()\r\n
at Microsoft.LightSwitch.ServerGenerated.Implementation.DataService`1.<>c__DisplayClasse.<Microsoft.LightSwitch.ServerGenerated.Implementation.IODataService.SaveChanges>b__c()\r\n
at Microsoft.LightSwitch.ServerGenerated.Implementation.DataServiceImplementation`1.InvokeOperationCore[T](String operationName, Object[] args, Boolean invokedFromODataClient, Func`1 invokeOperation, Action catchCallback, Action`2 serializeCustomExceptionInfo)</StackTrace><ErrorInfo /></ExceptionInfo>"}}}
--changesetresponse_d1537003-f0cd-4fe2-b4b1-2f562b3179d0--
--batchresponse_663f69c3-6315-447b-b179-00bf407c3b09--
Web API からのログ:
iisexpress.exe Information: 0 : Request, Method=POST, Url=http://localhost:3346/odata/$batch, Message='http://localhost:3346/odata/$batch'
iisexpress.exe Information: 0 : Request, Method=POST, Url=http://localhost:3346/odata/ServiceProviders, Message='http://localhost:3346/odata/ServiceProviders'
iisexpress.exe Information: 0 : Message='Will use same 'JsonMediaTypeFormatter' formatter', Operation=JsonMediaTypeFormatter.GetPerRequestFormatterInstance
iisexpress.exe Information: 0 : Message='Selected formatter='JsonMediaTypeFormatter', content-type='application/json; charset=utf-8'', Operation=DefaultContentNegotiator.Negotiate
iisexpress.exe Information: 0 : Operation=InspectHandler.SendAsync, Status=400 (BadRequest)
iisexpress.exe Information: 0 : Response, Status=400 (BadRequest), Method=POST, Url=http://localhost:3346/odata/ServiceProviders, Message='Content-type='application/json; charset=utf-8', content-length=unknown'
iisexpress.exe Information: 0 : Operation=InspectHandler.SendAsync, Status=202 (Accepted)
iisexpress.exe Information: 0 : Response, Status=202 (Accepted), Method=POST, Url=http://localhost:3346/odata/$batch, Message='Content-type='multipart/mixed; boundary=batchresponse_580061e2-8dc6-4676-b207-1b6ad0ff8847', content-length=unknown'
iisexpress.exe Information: 0 : Operation=JsonMediaTypeFormatter.WriteToStreamAsync