I've got a DomainService that I've created from an entity framework that's being exposed via a JSON endpoint. I can successfully do GET operations but whenever I try to POST to them using JSON the objects are always null.
The code below is used to create a user record in my database:
[Invoke]
public void CreateUser(User NewUser)
{
if (!DoesUserExist(NewUser.DisplayName))
{
ObjectContext.Users.AddObject(NewUser);
}
}
Which is called from my Silverlight application via this code:
DataContractJsonSerializer UserSerializer = new DataContractJsonSerializer(typeof(User));
MemoryStream MS = new MemoryStream();
UserSerializer.WriteObject(MS, NewUser);
StreamReader Reader = new StreamReader(MS);
MS.Position = 0;
string JSON = Reader.ReadToEnd();
WebClient CreateUser = new WebClient();
CreateUser.UploadStringCompleted += CreateUserCompleted;
CreateUser.Headers["Content-type"] = "application/json";
CreateUser.Encoding = Encoding.UTF8;
CreateUser.UploadStringAsync(new Uri("http://localhost/NewApp-web-api.svc/json/CreateUser"), "POST", JSON);
When debugging the DomainService I can see that the service gets hit however the NewUser object is always NULL. I've done some digging and seen a couple people saying they need to add a wrapper around the JSON string but no specifics about what they actually did.
Is what I'm trying to do even possible? It seems like I could accomplish this via an AJAX enabled WCF service however I lose the integration with the ObjectContext.
Thanks in advance :)