Can some one tell me how to post request to a wcf rest service? my code is below
TResponse Post<TRequest, TResponse>(string uri, TRequset input){
HttpClient client = new HttpClient();
HttpContent content = new ObjectContent<TRequest>(input, new XmlMediaTypeFormatter());
HttpResponseMessage message = client.PostAsync(uri, content).Result;
return message.Content.ReadAsAsync<TResponse>().Result;
}
but it gives following exception
System.InvalidOperationException was unhandled by user code
HResult=-2146233079
Message=No MediaTypeFormatter is available to read an object of type 'String' from content with media type 'text/html'.
Source=System.Net.Http.Formatting
and the value of message variable is
message {StatusCode: 400, ReasonPhrase: 'Bad Request', Version: 1.1, Content: System.Net.Http.StreamContent, Headers:
{
Connection: Close
Cache-Control: private
Date: Wed, 19 Dec 2012 14:36:32 GMT
Server: ASP.NET
Server: Development
Server: Server/10.0.0.0
X-AspNet-Version: 4.0.30319
Content-Length: 1766
Content-Type: text/html
}} System.Net.Http.HttpResponseMessage
i know wcf rest is deprecated. But can some one pls tell me how to implement this? thx