Error org.xmlpull.v1.Xmlpullparserexception: expected: START_TAG

Asked

Viewed 126 times

1

Good night, you guys! I’m developing an android application that should connect with a c#webservice, but I’m having some problems connecting with my webservice.

When I put the W3c webservice to test the connection works perfectly, but when I put mine does not work, I would like a light.

My Webservice:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Script.Serialization;
using System.Web.Script.Services;
using System.Web.Services;

namespace WebServices
{
    /// <summary>
    /// Summary description for wsEmbargo
    /// </summary>
    [WebService(Namespace = "http://www.incomisa.com.br/")]
    [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
    [System.ComponentModel.ToolboxItem(false)]
    // To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the following line. 
// [System.Web.Script.Services.ScriptService]
public class wsEmbargo : System.Web.Services.WebService
{
    [WebMethod]
    public string EfetuaLogin()
    {
        /*JavaScriptSerializer js = new JavaScriptSerializer();
        Usuario lg = new Usuario();

        lg.resultado = "lpontes";

        return js.Serialize(lg);*/
        return "1";
    }

    private class Usuario
    {
        public string resultado { get; set; }
    }
}
}

My connection:

package br.com.alura.embargo;

import android.app.ProgressDialog;
import android.content.Intent;
import android.os.AsyncTask;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.Toast;

import org.json.JSONArray;
import org.json.JSONException;

import org.json.JSONObject;
import org.ksoap2.SoapEnvelope;
import org.ksoap2.serialization.SoapObject;
import org.ksoap2.serialization.SoapSerializationEnvelope;
import org.ksoap2.transport.HttpTransportSE;
import org.xmlpull.v1.XmlPullParserException;

import java.io.IOException;

public class LoginActivity extends AppCompatActivity {

private ProgressDialog dialogo;

private static final String SOAP_ACTION="http://www.incomisa.com.br/EfetuaLogin";
private static final String NAMESPACE="http://www.incomisa.com.br/";
private static final String METHOD_NAME="EfetuaLogin";
private static String URL="http://vpn1.incomisa.com.br:95/wsEmbargo.asmx";

private String retornoUsuario;

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

    Button logar = (Button) findViewById(R.id.btnSignUp);

    logar.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            new asynProjeto().execute();
        }
    });
}

class asynProjeto extends AsyncTask<String, String, String> {

    @Override
    protected void onPreExecute() {
        dialogo = new ProgressDialog(LoginActivity.this);
        dialogo.setMessage("Carregando dados...");
        dialogo.setIndeterminate(false);
        dialogo.setCancelable(false);
        dialogo.show();
    }

    @Override
    protected String doInBackground(String... strings) {
        /*if(invocaWS()) {
            return "ok";
        }else{
            return "erro";
        }*/

        String re = "ok";

        try{
            SoapObject resposta = new SoapObject(NAMESPACE, METHOD_NAME);
            SoapSerializationEnvelope sobre = new SoapSerializationEnvelope (SoapEnvelope.VER11);
            sobre.dotNet = true;
            sobre.setOutputSoapObject(resposta);
            HttpTransportSE transportSE = new HttpTransportSE(URL);
            transportSE.debug = true;
            transportSE.call(SOAP_ACTION, sobre);

            //SoapObject res = (SoapObject) sobre.getResponse();
            String resultado = sobre.getResponse().toString();
            JSONArray json = new JSONArray(resultado);

            JSONObject jsonObj = json.getJSONObject(0);
            retornoUsuario = jsonObj.getString("resultado");

        }
        catch(IOException e){
            e.printStackTrace();
            re = "erro";
        }
        catch (XmlPullParserException e){
            e.printStackTrace();
            re = "erro";
        }
        catch (JSONException e){
            e.printStackTrace();
            re = "erro";
        }
        catch (Exception e) {
            e.printStackTrace();
            re = "erro";
        }
    return re;
    }

    @Override
    protected void onPostExecute(String s){
        dialogo.dismiss();
        if(s.equals("ok")) {
            Intent intent = new Intent(LoginActivity.this, MainActivity.class);
            startActivity(intent);

            Toast.makeText(LoginActivity.this, "Usuário autenticado com sucesso!", Toast.LENGTH_SHORT).show();
        }else{
            Log.e("Script", "Deu errado: " + s.toString());
        }
    }


}

public Boolean invocaWS() {
    Boolean re = false;

    try{
        SoapObject resposta = new SoapObject(NAMESPACE, METHOD_NAME);
        SoapSerializationEnvelope sobre = new SoapSerializationEnvelope (SoapEnvelope.VER11);
        sobre.dotNet = true;
        HttpTransportSE transportSE = new HttpTransportSE(URL);
        transportSE.call(SOAP_ACTION, sobre);

        //SoapObject res = (SoapObject) sobre.getResponse();
        String resultado = sobre.getResponse().toString();
        JSONArray json = new JSONArray(resultado);

        JSONObject jsonObj = json.getJSONObject(0);
        retornoUsuario = jsonObj.getString("resultado");

    }
    catch(IOException e){
        e.printStackTrace();
        re = false;
    }
    catch (XmlPullParserException e){
        e.printStackTrace();
        re = false;
    }
    catch (JSONException e){
        e.printStackTrace();
        re = false;
    }
    return re;
}
}

The mistake is in this line: transportSE.call(SOAP_ACTION, sobre);

Fall for this catch:

catch (XmlPullParserException e){
            e.printStackTrace();
            re = "erro";
        }

with this error message:

org.xmlpull.v1.XmlPullParserException: expected: START_TAG {http://schemas.xmlsoap.org/soap/envelope/}Envelope (position:START_TAG <html>@2:7 in java.io.InputStreamReader@f982c6d) 

I’m stuck in this, I don’t know what else to do, I’ve read several forums and tutorials. I believe the error is in my WS, since the W3C works normally.

  • 1

    I may be mistaken, but it seems that by the error message, it seems that returning an html, see this answer http://stackoverflow.com/q/5791337/1518921 (I don’t know much about this to formulate a good answer), I hope it helps.

  • Which address of your WS?

  • Blz Guilherme I will test this and put the result.

  • Esse aqui Paulo: private Static String URL="http://vpn1.incomisa.com.br:95/wsEmbargo.asmx";

No answers

Browser other questions tagged

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