Response status code does not indicate success: 400 (Bad Request).
at System.Net.Http.HttpResponseMessage.EnsureSuccessStatusCode()
at SmartShop.Utils.Rest.RestHelper.PostCallRestfulService[T](String webApiUriRoot, String functionUri, Object requestObj) in d:\rduan\365\Xian\Shared\SmartShop.Utilities\Src\SmartShop.Utils\Rest\RestHelper.cs:line 39
亲,请问这是什么问题呢,我也不知道怎么坏的。
public static T PostCallRestfulService<T>(string webApiUriRoot, string functionUri, object requestObj) { HttpResponseMessage response = null; try { using (var client = new HttpClient()) { client.BaseAddress = new Uri(webApiUriRoot); client.DefaultRequestHeaders.Accept.Clear(); client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json")); response = client.PostAsJsonAsync("api/" + functionUri, requestObj).Result; response.EnsureSuccessStatusCode(); var resultContent = response.Content.ReadAsAsync<T>(); return resultContent.Result; } } catch { if (response != null && response.StatusCode == System.Net.HttpStatusCode.Unauthorized) { throw new UnauthorizedException(); } throw; } }
要么是调用的WCF服务的URL不对,要么是WCF服务端出了问题
你服务是独立的么?还是在项目里。如果有改动服务里的方法,需要生成服务文件,才生效额。实在不行,删掉webconfig里的引用,删掉Bin下的引用,重新引用试试。