Base solution for your next web application
Open Closed

How does ABP provide interface to Android or others #257


User avatar
0
vallygao created

Hi, Recently, I got a problem that how does ABP provide interface to Android or others. RE, I have a interface like ".../api/services/Assistant/customer/getAllCustomer",and this method with parameter state. How to call the web API directly? How to pass parameters? How web API receive parameters?

Please help me!


5 Answer(s)
  • User Avatar
    0
    hikalkan created
    Support Team

    Hi,

    You can always create regular web api controller and call them from any platform. For dynamic web api layer, it should be called with POST and with JSON input/output. Just call .../api/services/Assistant/customer/getAllCustomer with POST and get JSON result.

  • User Avatar
    0
    vallygao created

    Thanks for your reply. :D I have added a web api controller,but it still has something confusing me :(

    when use the method get ,it's all ok. use the method post without parameter,it' s still noting wrong. but when use the method post with parameters,it returns error"an internal error occured during your request"

    here's my code: controller:

    public class ContactController : AbpApiController
        {
            Contact[] contacts = new Contact[] { 
                new Contact(){ ID=1, Age=23, Birthday=Convert.ToDateTime("1977-05-30"), Name="Jone", Sex="M"},
                new Contact(){ ID=2, Age=55, Birthday=Convert.ToDateTime("1937-05-30"), Name="Brown", Sex="M"},
                new Contact(){ ID=3, Age=12, Birthday=Convert.ToDateTime("1987-05-30"), Name="Lily", Sex="F"},
                new Contact(){ ID=4, Age=18, Birthday=Convert.ToDateTime("1997-05-30"), Name="Lucy", Sex="F"},
            };
    
            [HttpGet]
            public virtual IEnumerable<Contact> GetListAll()
            {
                return contacts;
            }
    
            [HttpPost]
            public virtual IEnumerable<Contact> QueryLists([FromBody]int state)
            {
                return contacts.Where(con=>con.ID==state);
            }
      }
    

    the method get:

    $('#send_ajax').click(function(){
                    $.ajax({
                        url:'http://...../api/Contact/GetListAll',
                        type:'get',
                        data:{},
                        success:function(data){
                            //alert(data);
                        },
                        error:function(data){
                            //var myjson='';
                        }
                    });
                });
    

    the result:

    [{"id":1,"name":"Jone","sex":"M","birthday":"1977-05-30T00:00:00","age":23},{"id":2,"name":"Brown","sex":"M","birthday":"1937-05-30T00:00:00","age":55},{"id":3,"name":"Lily","sex":"F","birthday":"1987-05-30T00:00:00","age":12},{"id":4,"name":"Lucy","sex":"F","birthday":"1997-05-30T00:00:00","age":18}]
    

    the method post :

    $('#send_ajax').click(function(){
                    $.ajax({
                        url:'http://....../api/Contact/QueryLists',
                        type:'post',
                        data:{"state":1},
                        success:function(data){
                            //alert(data);
                        },
                        error:function(data){
                        }
                    });
                });
    

    the result:

    {"success":false,"result":null,"error":{"code":0,"message":"An internal error occurred during your request!","details":null,"validationErrors":null},"unAuthorizedRequest":false}
    

    Do you have some solutions ?waitting for your good news.

  • User Avatar
    0
    hikalkan created
    Support Team

    Have you checked the internal error? You can find it in Logs folder in web project.

  • User Avatar
    0
    vallygao created

    yes,i did. but i don't understand what causes.here's the log:

    ERROR 2015-08-03 16:09:30,907 [73   ] lers.Filters.AbpExceptionFilterAttribute - System.Web.Http.HttpResponseException: Processing of the HTTP request resulted in an exception. Please see the HTTP response returned by the 'Response' property of this exception for details.
       在 System.Web.Http.ModelBinding.FormatterParameterBinding.ReadContentAsync(HttpRequestMessage request, Type type, IEnumerable`1 formatters, IFormatterLogger formatterLogger, CancellationToken cancellationToken)
       在 System.Web.Http.ModelBinding.FormatterParameterBinding.ReadContentAsync(HttpRequestMessage request, Type type, IEnumerable`1 formatters, IFormatterLogger formatterLogger)
       在 System.Web.Http.ModelBinding.FormatterParameterBinding.<ExecuteBindingAsyncCore>d__0.MoveNext()
    --- 引发异常的上一位置中堆栈跟踪的末尾 ---
       在 System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
       在 System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
       在 System.Web.Http.Controllers.HttpActionBinding.<ExecuteBindingAsyncCore>d__0.MoveNext()
    --- 引发异常的上一位置中堆栈跟踪的末尾 ---
       在 System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
       在 System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
       在 System.Web.Http.Controllers.ActionFilterResult.<ExecuteAsync>d__2.MoveNext()
    --- 引发异常的上一位置中堆栈跟踪的末尾 ---
       在 System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
       在 System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
       在 System.Web.Http.Controllers.ExceptionFilterResult.<ExecuteAsync>d__0.MoveNext()
    System.Web.Http.HttpResponseException: Processing of the HTTP request resulted in an exception. Please see the HTTP response returned by the 'Response' property of this exception for details.
       在 System.Web.Http.ModelBinding.FormatterParameterBinding.ReadContentAsync(HttpRequestMessage request, Type type, IEnumerable`1 formatters, IFormatterLogger formatterLogger, CancellationToken cancellationToken)
       在 System.Web.Http.ModelBinding.FormatterParameterBinding.ReadContentAsync(HttpRequestMessage request, Type type, IEnumerable`1 formatters, IFormatterLogger formatterLogger)
       在 System.Web.Http.ModelBinding.FormatterParameterBinding.<ExecuteBindingAsyncCore>d__0.MoveNext()
    --- 引发异常的上一位置中堆栈跟踪的末尾 ---
       在 System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
       在 System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
       在 System.Web.Http.Controllers.HttpActionBinding.<ExecuteBindingAsyncCore>d__0.MoveNext()
    --- 引发异常的上一位置中堆栈跟踪的末尾 ---
       在 System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
       在 System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
       在 System.Web.Http.Controllers.ActionFilterResult.<ExecuteAsync>d__2.MoveNext()
    --- 引发异常的上一位置中堆栈跟踪的末尾 ---
       在 System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
       在 System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
       在 System.Web.Http.Controllers.ExceptionFilterResult.<ExecuteAsync>d__0.MoveNext()
    
  • User Avatar
    0
    hikalkan created
    Support Team

    This seems not related to ABP. But you can try a few things more to know what's is the error:

    1. Check docs: <a class="postlink" href="http://www.aspnetboilerplate.com/Pages/Documents/Handling-Exceptions#DocExceptionEvent">http://www.aspnetboilerplate.com/Pages/ ... ptionEvent</a> (Exception event section) to get handled exception details. You can add a breakpoint into HandleEvent and check eventData.Exception object.

    2. Check network tab of Chrome to see returned result in detail.