Trouble using JsonHttpClient with POST

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

The urlBase should only be the BaseUrl for all your ServiceStack Services, i.e. Not a url to any specific request. Try changing it to:

//I'm assuming this is the BaseUrl 
string urlBase = "http://localhost:32070/api/"; 

//The relative path needs to be from the BaseUrl
var resp = client.Get<GetPropertyResponse>("/v1/property/12402-3230");

//...

//You don't need to specify Response Type when using IReturn<T> marker, e.g:
var resp2 = client.Put(prop); 

I’d also recommend using a Typed Request DTO instead of using a relative path, e.g:

var resp = client.Get(new GetProperty { Id = "12402-3230" });

Also using a tool like R# is helpful in showing which boilerplate code is unnecessary and can be inferred.

The error suggests that the Request that was sent was invalid, when hitting interop issues like this the easiest way to diagnose it is to look at the underlying HTTP Request using something like Fiddler which would be able to show exactly what was wrong with the Request.