I send the following ODATA message:
_DELETE http://localhost:34852/Tags(guid'43e361ba-a8a0-4dbe-8474-dfcb5496c161') HTTP/1.1__
DataServiceVersion: 3.0
MaxDataServiceVersion: 3.0
Host: localhost:34852
I get back an error:
HTTP/1.1 400 Bad Request
Cache-Control: no-cache
Pragma: no-cache
Content-Type: application/json; odata=minimalmetadata; streaming=true; charset=utf-8
Expires: -1
Server: Microsoft-IIS/8.0
DataServiceVersion: 3.0
X-AspNet-Version: 4.0.30319
X-SourceFiles: =?UTF-8?B?QzpcY3BtU291cmNlc1xLbm93bGVkZ2UgTWFuYWdlclxEZXZlbG9wbWVudFxEYXRhU2VydmljZVByb3RvdHlwZVxXZWJBcGlEYXRhU2VydmljZVxQaW1zQ29uZmlnRGF0YVN2Y1xBQkIuUElNUy5TZXJ2ZXIuQ29uZmlnU2VydmljZVxUYWdzKGd1aWQnNDNlMzYxYmEtYThhMC00ZGJlLTg0NzQtZGZjYjU0OTZjMTYxJyk=?=
X-Powered-By: ASP.NET
Date: Tue, 05 Mar 2013 11:36:20 GMT
Content-Length: 561
{
"odata.error":{
"code":"","message":{
"lang":"en-US","value":"The request is invalid."
},"innererror":{
"message":"The parameters dictionary contains a null entry for parameter 'key' of non-nullable type 'System.Guid' for method 'Void Delete(System.Guid)' in 'ABB.PIMS.Server.ConfigService.Controllers.Base.StoreEntitySetController`2[ABB.PIMS.Data.Model.Domain.RTDB.Tag,System.Guid]'. An optional parameter must be a reference type, a nullable type, or be declared as an optional parameter.","type":"","stacktrace":""
}
}
}
The error happens before any of the(standard and custom) routing conventions are evaluated.
GetByKey works correctly.
I use the released version of WebApi OData (v4.0.30319). See attachment for relevant trace log part.
Comments: So I've been stepping through the WebAPI source - all a very new thing to me as this is my first experience with WebAPI and I've already hit a problem - and have found that the ValueProviderResult.ConvertSimpleType(....) method is one place where this can be fixed. It already has a couple of special case checks for things like an empty string and enums so I added another for cases where we have a string beginning with guid' and ending with a single ' and are mapping it to a Guid. I strip the leading guid' and trailing ' from the value parameter and let the method continue as normal. Following through the code it seems I could implement a custom ModelBinder and ModelBinderProvider as in the one at the bottom of the page at http://forums.asp.net/t/1770906.aspx/1?How+do+I+add+a+custom+ModelBinder. I'm going to try that next - I suppose if this works then the WebAPI OData support itself should have such a ModelBinder provided out of the box to handle the Guid case.
_DELETE http://localhost:34852/Tags(guid'43e361ba-a8a0-4dbe-8474-dfcb5496c161') HTTP/1.1__
DataServiceVersion: 3.0
MaxDataServiceVersion: 3.0
Host: localhost:34852
I get back an error:
HTTP/1.1 400 Bad Request
Cache-Control: no-cache
Pragma: no-cache
Content-Type: application/json; odata=minimalmetadata; streaming=true; charset=utf-8
Expires: -1
Server: Microsoft-IIS/8.0
DataServiceVersion: 3.0
X-AspNet-Version: 4.0.30319
X-SourceFiles: =?UTF-8?B?QzpcY3BtU291cmNlc1xLbm93bGVkZ2UgTWFuYWdlclxEZXZlbG9wbWVudFxEYXRhU2VydmljZVByb3RvdHlwZVxXZWJBcGlEYXRhU2VydmljZVxQaW1zQ29uZmlnRGF0YVN2Y1xBQkIuUElNUy5TZXJ2ZXIuQ29uZmlnU2VydmljZVxUYWdzKGd1aWQnNDNlMzYxYmEtYThhMC00ZGJlLTg0NzQtZGZjYjU0OTZjMTYxJyk=?=
X-Powered-By: ASP.NET
Date: Tue, 05 Mar 2013 11:36:20 GMT
Content-Length: 561
{
"odata.error":{
"code":"","message":{
"lang":"en-US","value":"The request is invalid."
},"innererror":{
"message":"The parameters dictionary contains a null entry for parameter 'key' of non-nullable type 'System.Guid' for method 'Void Delete(System.Guid)' in 'ABB.PIMS.Server.ConfigService.Controllers.Base.StoreEntitySetController`2[ABB.PIMS.Data.Model.Domain.RTDB.Tag,System.Guid]'. An optional parameter must be a reference type, a nullable type, or be declared as an optional parameter.","type":"","stacktrace":""
}
}
}
The error happens before any of the(standard and custom) routing conventions are evaluated.
GetByKey works correctly.
I use the released version of WebApi OData (v4.0.30319). See attachment for relevant trace log part.
Comments: So I've been stepping through the WebAPI source - all a very new thing to me as this is my first experience with WebAPI and I've already hit a problem - and have found that the ValueProviderResult.ConvertSimpleType(....) method is one place where this can be fixed. It already has a couple of special case checks for things like an empty string and enums so I added another for cases where we have a string beginning with guid' and ending with a single ' and are mapping it to a Guid. I strip the leading guid' and trailing ' from the value parameter and let the method continue as normal. Following through the code it seems I could implement a custom ModelBinder and ModelBinderProvider as in the one at the bottom of the page at http://forums.asp.net/t/1770906.aspx/1?How+do+I+add+a+custom+ModelBinder. I'm going to try that next - I suppose if this works then the WebAPI OData support itself should have such a ModelBinder provided out of the box to handle the Guid case.