Below is my wcf service.
public ApiResponseWrapper<TextBlobModel> PostText(string sessionId, string profileId, TextBlobModel txtModel)
{}
The interface part for this
[OperationContract]
[WebInvoke(Method = "POST", ResponseFormat = WebMessageFormat.Json, BodyStyle = WebMessageBodyStyle.Bare, UriTemplate = "session/{sessionId}/profile/{profileId}/text")]
ApiResponseWrapper<TextBlobModel> PostText(string sessionId, string profileId, TextBlobModel txtModel);
And model
[DataContract]
public class TextBlobModel
{
[DataMember]
public string text { get; set; }
[DataMember]
public DateTime receivedTime { get; set; }
}
When I called the service above as follows, I always get a bad request error.
var baseApiUrl = "http://localhost:51398/api.svc/";
HttpClient authClient = new HttpClient();
authClient.BaseAddress = new Uri(baseoAuthApiUrl);
apiClient.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
var txtModel = new TextBlobModel();
txtModel.text = "Hello How are you";
txtModel.receivedTime = DateTime.Now;
HttpResponseMessage txtResponse = apiClient.PostAsJsonAsync(String.Format("session/{0}/profile/{1}/text", "sessionId", "profileId"), txtModel).Result;
var txtData = txtResponse.Content.ReadAsAsync<RootObject>().Result;
See the following image.

Could you suggest what I am doing wrong here?
source
share