Issue
I'm trying to consume a WCF RESTful Service hosted in IIS on Android using Volley. I have the next code:
private static final String URL_BASE = "http://10.0.3.2/SimpleRESTServiceCRUD/BookService.svc";
private static final String URL_JSON = "/Books";
List<Book> items;
JsonObjectRequest jsArrayRequest;
private RequestQueue requestQueue;
public BookAdapter(Context context)
{
super(context,0);
requestQueue = Volley.newRequestQueue(context);
JsonObjectRequest jsArrayRequest = new JsonObjectRequest(
Request.Method.GET,
URL_BASE + URL_JSON,
null,
new Response.Listener<JSONObject>() {
@Override
public void onResponse(JSONObject response) {
items = parseJson(response);
notifyDataSetChanged();
}
},
new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
Log.d(TAG, "Error on JSON response: " + error.getMessage());
}
}
);
}
But when I'm debugging always get new Response.ErrorListener()
BUT never gets into:
@Override
public void onErrorResponse(VolleyError error) {
Log.d(TAG, "Error on JSON response: " + error.getMessage());
}
So I can't know what happened!! I'm using Genymotion Emulator, so I tried this Uris:
http://192.168.56.1/SimpleRESTServiceCRUD/BookService.svc
http://10.0.3.2/SimpleRESTServiceCRUD/BookService.svc
I even used the Mobile Browser to see if it's working, and I actually could get to the service.
If anyone could give me a hand I will really appreciate. Thanks!!
Solution
I think your request has not been sent to the WCF Service, because you don't have the following line:
requestQueue.add(jsArrayRequest);
So, update your code as the following:
public BookAdapter(Context context)
{
super(context,0);
requestQueue = Volley.newRequestQueue(context);
JsonObjectRequest jsArrayRequest = new JsonObjectRequest(
Request.Method.GET,
URL_BASE + URL_JSON,
null,
new Response.Listener<JSONObject>() {
@Override
public void onResponse(JSONObject response) {
items = parseJson(response);
notifyDataSetChanged();
}
},
new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
Log.d(TAG, "Error on JSON response: " + error.getMessage());
}
}
);
requestQueue.add(jsArrayRequest);
}
Hope this helps!
Answered By - BNK
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.