Skip to content

Instantly share code, notes, and snippets.

View pedroreys's full-sized avatar

Pedro Reys pedroreys

View GitHub Profile
@pedroreys
pedroreys / Issue_Description.md
Created May 22, 2012 17:06
Self Host Web API Model Binding Issue

I have a self hosted web api that has a controller with a Post action that takes a single string argument.

Model binding is failing to set the value of the argument and it's being passed null, even though the value is correct in the HttpContent object.

Below are a Controller and a test that reproduces the issue.

This bug was filled on codeplex: http://aspnetwebstack.codeplex.com/workitem/171

UPDATE

@pedroreys
pedroreys / gist:2229908
Created March 28, 2012 19:48
strong name log
Microsoft (R) .NET Framework Strong Name Utility Version 4.0.30319.1
Copyright (c) Microsoft Corporation. All rights reserved.
Assembly/Strong Name Users
===========================================
Microsoft.TestCommon,31bf3856ad364e35 All users
Microsoft.Web.Helpers,31bf3856ad364e35 All users
Microsoft.Web.Helpers.Test,31bf3856ad364e35 All users
Microsoft.Web.Http.Data,31bf3856ad364e35 All users
@pedroreys
pedroreys / gist:2229376
Created March 28, 2012 18:51
aspnetwebstack build log
Microsoft (R) Build Engine Version 4.0.30319.1
[Microsoft .NET Framework, Version 4.0.30319.261]
Copyright (C) Microsoft Corporation 2007. All rights reserved.
System.Web.Razor -> C:\dev\aspnetwebstack\bin\Release\System.Web.Razor.dll
System.Web.WebPages.Deployment -> C:\dev\aspnetwebstack\bin\Release\System.Web.WebPages.Deployment.dll
WebMatrix.Data -> C:\dev\aspnetwebstack\bin\Release\WebMatrix.Data.dll
Microsoft.TestCommon -> C:\dev\aspnetwebstack\bin\Release\Test\Microsoft.TestCommon.dll
System.Json -> C:\dev\aspnetwebstack\bin\Release\System.Json.dll
System.Net.Http.Formatting -> C:\dev\aspnetwebstack\bin\Release\System.Net.Http.Formatting.dll
@pedroreys
pedroreys / gist:2173894
Created March 23, 2012 19:05
WebAPIContrib Transitions
public interface IApiResource {
void SetLocation(ResourceLocation resourceLocation);
void SetTransitions(ResourceTransitions transitions);
}
public class Order : IApiResource {
public int Id { get; set; }
// other resource members ...
public HttpResponseMessage<Contact> Post(Contact contact)
{
this.repository.Post(contact);
return new CreateResponse<Contact>(contact, this.ControllerContext);
}
System.NotSupportedException was caught
Message=This operation is only supported by directly calling it on 'RouteCollection'.
Source=System.Web.Http.WebHost
StackTrace:
at System.Web.Http.WebHost.Routing.HostedHttpRouteCollection.GetEnumerator()
at WebApiContrib.Internal.RoutingHelper.GetUriFor(RouteValueDictionary routeValues, HttpControllerContext controllerContext) in C:\dev\WebAPIContrib\src\WebApiContrib\Internal\RoutingHelper.cs:line 42
InnerException:
public string Route(
string routeName,
IDictionary<string, Object> routeValues
)
public SetLocation(ResourceLocation location)
{
location.SetIn<ContactsController>(x => x.Get(Id));
}
public class Contact : IApiResource
{
public int Id { get; set; }
// ... other Contact Members
public SetLocation(ResourceLocation location)
{
location.Location = new Uri("http://api.contoso.com/contacts/"+Id);
}
}
public interface IApiResource
{
void SetLocation(ResourceLocation location);
}
public class ResourceLocation
{
public Uri Location { get; private set; }