首页 新闻 赞助 找找看

WCF 抛异常啦,400,我不知道怎么搞坏的。

0
悬赏园豆:20 [已关闭问题] 关闭于 2015-05-27 13:00

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
Eysa的主页 Eysa | 初学一级 | 园豆:62
提问于:2015-05-19 11:21
< >
分享
所有回答(2)
0

要么是调用的WCF服务的URL不对,要么是WCF服务端出了问题

dudu | 园豆:31075 (高人七级) | 2015-05-19 11:30
0

你服务是独立的么?还是在项目里。如果有改动服务里的方法,需要生成服务文件,才生效额。实在不行,删掉webconfig里的引用,删掉Bin下的引用,重新引用试试。

大楚打码人 | 园豆:4313 (老鸟四级) | 2015-05-19 13:44
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册