2014-10-21 3 views
2

Cors를 사용할 수있는 WebAPI가 있습니다.WebAPI에서 참조 된 dll을 호출하면 로컬에서는 작동하지만 서버에서는 작동하지 않습니다.

내 webAPI 내가의 처리를 많이 할 클래스 라이브러리를 참조합니다.이 오류를 던지는 WebAPI 및 클래스 라이브러리와도 클래스 라이브러리 내부의 호출은

사이

전화를 ...

{"Message":"An error has occurred.","ExceptionMessage":"Object reference not set to an instance of an object.", 
"ExceptionType":"System.NullReferenceException","StackTrace":" 
at RCIS.MappingServices.WebAPI.Utilities.SQL.SQLInsertObjects(Int32 TypeMapId, Int32 GrowerId, Int32 CropYear, String NAME, String SHAPE, String CREATED_BY, String CREATED_DATETIME, String MODIFIED_BY, String MODIFIED_DATETIME, String IsDELETED)\r\n 
at RCIS.MappingServices.WebAPI.Controllers.PostObjectsController.GET(String TypeMapId, String GrowerId, String CropYear, String NAME, String SHAPE)\r\n 
at lambda_method(Closure , Object , Object[])\r\n 
at System.Web.Http.Controllers.ReflectedHttpActionDescriptor.ActionExecutor.<>c__DisplayClass10.<GetExecutor>b__9(Object instance, Object[] methodParameters)\r\n 
at System.Web.Http.Controllers.ReflectedHttpActionDescriptor.ActionExecutor.Execute(Object instance, Object[] arguments)\r\n at System.Web.Http.Controllers.ReflectedHttpActionDescriptor.ExecuteAsync(HttpControllerContext controllerContext, 
IDictionary`2 arguments, CancellationToken cancellationToken)\r\n--- End of stack trace from previous location where exception was thrown ---\r\n 
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)\r\n 
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n 
at System.Web.Http.Controllers.ApiControllerActionInvoker.<InvokeActionAsyncCore>d__0.MoveNext()\r\n--- End of stack trace from previous location where exception was thrown ---\r\n 
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)\r\n 
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n 
at System.Web.Http.Controllers.ActionFilterResult.<ExecuteAsync>d__2.MoveNext()\r\n--- End of stack trace from previous location where exception was thrown ---\r\n 
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)\r\n 
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n 
at System.Web.Http.Dispatcher.HttpControllerDispatcher.<SendAsync>d__1.MoveNext()"} 

이 만 나는 WebAPI 메소드를 호출 크롬에 URL을 입력하고 다시이 오류가 서버 (예)에서 클래스 라이브러리를 호출 할 때 발생하는 것으로 보인다.

WebAPI의 모든 기본 유형을 사용하고 클래스 라이브러리에서 성공 메시지를 다시받습니다.

질문 사항이 있으면 알려 주시기 바랍니다. 이것에 대한 도움은 크게 2 일 동안이 문제를 해결하기 위해 노력 해왔다!

+0

이 문제에 대한 해결책을 찾았습니까? 나는 비슷한 문제가있다. –

답변

0

전달할 문자열 값이 문자열 값인지 확인하십시오.

public class ErrorHelper : IHttpActionResult 
{ 
    private HttpRequestMessage Request { get; } 
    private HttpStatusCode statusCode; 
    private string message; 

    public ErrorHelper(HttpRequestMessage request, HttpStatusCode statusCode, string message) 
    { 
     this.Request = request; 
     this.statusCode = statusCode; 
     this.message = message; 
    } 

    public Task<HttpResponseMessage> ExecuteAsync(CancellationToken cancellationToken) 
    { 
     return Task.FromResult(Request.CreateErrorResponse(statusCode, message)); 
    } 
} 

다음과 같이 호출 :

public IHttpActionResult Get(int id) 
{ 
    try 
    { 
     var person = _repository.GetPersonId(id); 
     if (person == null) 
     { 
      return NotFound(); 
     } 
     return Ok(person); 
    } 
    catch (Exception ex) 
    { 
     return new ErrorHelper(Request, HttpStatusCode.InternalServerError, ex.ToString()); 
    } 
} 

이 당신에게 예외 정보를 줄 것이다

0

는 ErrorHelper을 확인합니다. 데이터베이스 드라이버 나 그와 비슷한 구성 요소가 서버에 설치되어 있지 않은 것 같습니다.

관련 문제