我創建了一個ASP.NET Web API,它將調用java web服務並在JSON中顯示一些結果。當java web服務未運行時,我收到錯誤消息:返回任務<IHttpActionResult>方法的JSON錯誤消息
{「Message」:「發生錯誤。」,「ExceptionMessage」:「方法或操作未實現。」, C:\ Users \ attsuap1 \ Desktop \ Server Project \ ApiClientJavaWebService \ ApiClientJavaWebService \ Models \ RestfulClient.cs中的ApiClientJavaWebService.Models.RestfulClient.InternalServerError(異常例外)中的「ExceptionType」:「System.NotImplementedException」,「StackTrace」在C:\ Users \ attsuap1 \ Desktop \ Server Project \ ApiClientJavaWebService \ ApiClientJavaWebService \ Models \ RestfulClient.cs中的ApiClientJavaWebService.Models.RestfulClient.d__3.MoveNext()中的第43行\ r \ n:第36行\ r \ n ---從拋出異常的上一個位置結束堆棧跟蹤--- System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(任務任務)中的\ r \ n \ System.Runtim中的\ r \ n e.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(任務任務)\ r \ n在System.Runtime.CompilerServices.TaskAwaiter 1.GetResult()\ r \ n在ApiClientJavaWebService.Controllers.AdditionController.d__1.MoveNext()在C:\ Users \ attsuap1 \ Desktop \ Server Project \ ApiClientJavaWebService \ ApiClientJavaWebService \ Controllers \ AdditionController.cs:第20行\ r \ n ---從以前位置拋出異常的堆棧跟蹤結束--- \ r \ n在System.Runtime.CompilerServices .TaskAwaiter.ThrowForNonSuccess(任務任務)\ r \ n在System.Threading.Tasks.TaskHelpersExtensions.d__3`1.MoveNext()\ r \ n System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(任務任務)\ r \ n ---從以前位置拋出異常的堆棧跟蹤結束---在System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(任務任務)上的\ r \ n在System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(任務任務)\ r \ n在System.Web.Http.Controllers.ApiControl lerActionInvoker.d__0.MoveNext()\ r \ n ---從之前的位置拋出異常的堆棧跟蹤結束--- \ r \ n在System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(任務任務)\ r \ n System.Web.Http.Controllers.ActionFilterResult.d__2.MoveNext()\ r \ n下System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(任務任務)\ r \ n ---以前位置的堆棧跟蹤結束,其中異常在System.Web的System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(任務任務)\ r \ n處,System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(任務任務)\ r \ n處拋出--- \ r \ n。 Http.Dispatcher.HttpControllerDispatcher.d__1.MoveNext()「}
我要如何改變這種去顯示爲{"The server is not running."}
錯誤信息?
這裏是我的代碼:
AdditionClient.cs
public class RestfulClient
{
private static HttpClient client;
private static string BASE_URL = "http://localhost:8080/";
static RestfulClient()
{
client = new HttpClient();
client.BaseAddress = new Uri(BASE_URL);
client.DefaultRequestHeaders.Accept.Add(
new MediaTypeWithQualityHeaderValue("application/json"));
}
public async Task<string> addition(int firstNumber, int secondNumber)
{
try
{
var endpoint = string.Format("addition/{0}/{1}", firstNumber, secondNumber);
var response = await client.GetAsync(endpoint);
return await response.Content.ReadAsStringAsync();
}
catch (Exception e)
{
}
return null;
}
}
AdditionController.cs
public class AdditionController : ApiController
{
private RestfulClient restfulClient = new RestfulClient();
public async Task<IHttpActionResult> Get(int firstNumber, int secondNumber)
{
var result = await restfulClient.addition(firstNumber, secondNumber);
var resultDTO = JsonConvert.DeserializeObject<Temp>(result);
return Json(resultDTO);
}
}
有人請你幫幫我。提前謝謝你。
你得到'System.NotImplementedException'。只要找到,你扔它 – Backs