Consume webservice C# amsx on android Volley

Asked

Viewed 528 times

0

I created a webservice in c# that returns me a string in the JSON pattern, I’m trying to consume this webservice with Volley but the same returns me null, depending on the variation of the url it returns me everything as if it were ? wsdl but not the function I want, it’s like the click on invoke is missing.

my url looks like this: = "http://10.0.2.2/webServiceFlux/WS/Sewrvicobase.asmx? op=fetch";

have tried url variations = "http://10.0.2.2/webServiceFlux/WS/Sewrvicobase.asmx among others

my code lies like this:

thank you all

package com.example.voleytest.voleytest;

import android.os.Bundle;
import android.support.v7.app.ActionBarActivity;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.TextView;
import android.widget.Toast;

import com.android.volley.Request;
import com.android.volley.RequestQueue;
import com.android.volley.Response;
import com.android.volley.VolleyError;
import com.android.volley.toolbox.StringRequest;
import com.android.volley.toolbox.Volley;

import java.util.HashMap;
import java.util.Map;


public class MainActivity extends ActionBarActivity {


       private RequestQueue queue;
    private String url;


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);


        url = "http://10.0.2.2/webServiceFlux/WS/SewrvicoBase.asmx?op=buscar";

        queue = Volley.newRequestQueue(MainActivity.this);

        callByJsonObjectRequest(null);
    }


    public void callByJsonObjectRequest(View view){

        // Request a string response from the provided URL.
        StringRequest stringRequest = new StringRequest(Request.Method.POST, url,
                new Response.Listener<String>() {
                    @Override
                    public void onResponse(String response) {
                        // Display the first 500 characters of the response string.

                        Toast.makeText(MainActivity.this, "Response is: " + response.substring(0, 500), Toast.LENGTH_LONG).show();
                    }
                }, new Response.ErrorListener() {
            @Override
            public void onErrorResponse(VolleyError error) {
                Toast.makeText(MainActivity.this, "Error: "+error.getMessage(), Toast.LENGTH_LONG).show();
            }




        }

        ) };
// Add the request to the RequestQueue.
        queue.add(stringRequest);


    }


    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.menu_main, menu);
        return true;
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        // Handle action bar item clicks here. The action bar will
        // automatically handle clicks on the Home/Up button, so long
        // as you specify a parent activity in AndroidManifest.xml.
        int id = item.getItemId();

        //noinspection SimplifiableIfStatement
        if (id == R.id.action_settings) {
            return true;
        }

        return super.onOptionsItemSelected(item);
    }
}
  • Rhelberth, I’m not sure using pure Volley is the best solution to consume a SOAP Webservice, I see a lot of people using the library ksoap2 or another specific library. Maybe you can even create a custom Volley Request/Response type to make the request asynchronous.

  • 'Cause I saw the ksoap myself, but does it work as well as Volley? I wouldn’t want to have to mess with trheads.

  • But if you combine ksoap with volley, using Custom Requests you can do the asynchronous request without having to explicitly manipulate Threads.

  • So let me get this straight, I use ksoap to get from my webservice and then play for Volley? Have you got any tutorial examples or etc? I was thinking of using web API solves the problem sera?

  • Yes and no. You would create a "layer" on top of Volley to make a Custom Request/Response to call ksoap. The example of this integration has in the link I passed, the ksoap part would have to see in the documentation of its repository.

  • All right, I got it, I was accessing the phone and had not seen the link, thanks for the information, know tell me if web api would be easier?

  • Unfortunately I do not know, let’s see if maybe someone can make an answer that addresses both ways.

Show 2 more comments
No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.