有人可以告诉我如何将请求发布到 wcf 休息服务吗?我的代码在下面
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;
}
但它给出了以下异常
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
消息变量的值为
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
我知道 wcf rest 已被弃用。但是有人可以告诉我如何实现吗?谢谢