I tried all options trying to understand why a simple PUT using ServiceStack’s JsonHttpClient does not work. The PUT webservice works fine when called from other sources (swagger, postman and even coded with RestSharp). Using v4.5.
The error I get is Handler not found with the inner exception saying:
{“Type definitions should start with a ‘{’, expecting serialized type ‘UpdatePropertyResponse’, got string starting with: Handler for Request not found (404):\n\r\n Request.H”}
Here is my code:
string urlBase = "http://localhost:32070/api/v1/property/12402-3230";
// Get a copy
var client = new ServiceStack.JsonHttpClient(urlBase);
GetPropertyResponse resp = client.Get<GetPropertyResponse>("");
// Modify it and save it back
UpdateProperty prop = new UpdateProperty();
prop = resp.Property.ConvertTo<UpdateProperty>();
prop.ResidenceTypeID = 2;
prop.StoriesID = 1;
prop.PropertyID = resp.Property.Id;
prop.Comment = "Testing";
var resp2 = client.Put<UpdatePropertyResponse>(prop); // EXCEPTION!!
string ans = resp2.ResponseStatus.ToString();
////////////////////////////////////////////////
The code for the webservice:
//**************************************
[Route("/v1/property/{PropertyID}", Verbs = "PUT")]
[AddHeader(ContentType = MimeTypes.Json)] // Return only JSON and exclude ServiceStack's HTML page
public class UpdateProperty : IReturn<UpdatePropertyResponse>
{
public string PropertyID { get; set; }
public int? ResidenceTypeID { get; set; }
public int? StoriesID { get; set; }
public int? StructureUseID { get; set; }
public string ParcelNumber { get; set; }
//other fields....
public string Comment { get; set; }
public string Reviewer { get; set; }
}
public class UpdatePropertyResponse
{
public tblProperty Property { get; set; }
public ResponseStatus ResponseStatus { get; set; }
}
public object Put(UpdateProperty request)
{
if (!Db.Exists<tblProperty>(x => x.Id == request.PropertyID))
{
throw HttpError.NotFound("Property not found");
}
tblProperty prop = request.ConvertTo<tblProperty>();
prop.Id = request.PropertyID;
Db.Update<tblProperty>(prop);
return new UpdatePropertyResponse
{
Property = prop
};
}
Thanks