Consuming webservice Soap on android

Asked

Viewed 919 times

1

I’m trying to consume a webservice but I’m in trouble.

I already tested in soapUI and the webservice is perfect, the problem is time to consume in Android Studio.

I got the following wsdl:

This XML file does not appear to have any style information associated with it. The document tree is shown below.
<!--
 Published by JAX-WS RI at http://jax-ws.dev.java.net. RI's version is Metro/2.2.0-1 (tags/2.2.0u1-7139; 2012-06-02T10:55:19+0000) JAXWS-RI/2.2.6-2 JAXWS/2.2 svn-revision#unknown. 
-->
<!--
 Generated by JAX-WS RI at http://jax-ws.dev.java.net. RI's version is Metro/2.2.0-1 (tags/2.2.0u1-7139; 2012-06-02T10:55:19+0000) JAXWS-RI/2.2.6-2 JAXWS/2.2 svn-revision#unknown. 
-->
<definitions xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd" xmlns:wsp="http://www.w3.org/ns/ws-policy" xmlns:wsp1_2="http://schemas.xmlsoap.org/ws/2004/09/policy" xmlns:wsam="http://www.w3.org/2007/05/addressing/metadata" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:tns="http://services.senior.com.br" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="http://schemas.xmlsoap.org/wsdl/" targetNamespace="http://services.senior.com.br" name="g5-senior-services">
<types>
<xsd:schema>
<xsd:import namespace="http://services.senior.com.br" schemaLocation="http://10.95.200.171:8000/g5-senior-services/rubi_Syncbr_com_cvale_Android?xsd=1"/>
</xsd:schema>
</types>
<message name="consultaLogin">
<part name="user" type="xsd:string"/>
<part name="password" type="xsd:string"/>
<part name="encryption" type="xsd:int"/>
<part name="parameters" type="tns:androidconsultaLoginIn"/>
</message>
<message name="consultaLoginResponse">
<part name="result" type="tns:androidconsultaLoginOut"/>
</message>
<portType name="rubi_Syncbr_com_cvale_Android">
<operation name="consultaLogin" parameterOrder="user password encryption parameters">
<input wsam:Action="http://services.senior.com.br/rubi_Syncbr_com_cvale_Android/consultaLoginRequest" message="tns:consultaLogin"/>
<output wsam:Action="http://services.senior.com.br/rubi_Syncbr_com_cvale_Android/consultaLoginResponse" message="tns:consultaLoginResponse"/>
</operation>
</portType>
<binding name="rubi_Syncbr_com_cvale_AndroidPortBinding" type="tns:rubi_Syncbr_com_cvale_Android">
<soap:binding transport="http://schemas.xmlsoap.org/soap/http" style="rpc"/>
<operation name="consultaLogin">
<soap:operation soapAction=""/>
<input>
<soap:body use="literal" namespace="http://services.senior.com.br"/>
</input>
<output>
<soap:body use="literal" namespace="http://services.senior.com.br"/>
</output>
</operation>
</binding>
<service name="g5-senior-services">
<port name="rubi_Syncbr_com_cvale_AndroidPort" binding="tns:rubi_Syncbr_com_cvale_AndroidPortBinding">
<soap:address location="http://10.95.200.171:8000/g5-senior-services/rubi_Syncbr_com_cvale_Android"/>
</port>
</service>
</definitions>

On android I have the following class:

public class ConvertService {
        private static final String SOAP_ACTION = "";
        private static final String METHOD_NAME = "consultaLogin";
        private static final String NAMESPACE = "http://services.senior.com.br/";
        private static final String URL = "http://10.95.200.171:8000/g5-senior-services/rubi_Syncbr_com_cvale_Android/";
        public String Convert(String user, String password, int encryption) {
            SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME);
            request.addProperty("user", user);
            request.addProperty("password", password);
            request.addProperty("encryption", encryption);
            SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
            envelope.dotNet = true;
            envelope.setOutputSoapObject(request);
            try {
                HttpTransportSE androidHttpTransport = new HttpTransportSE(URL);
                androidHttpTransport.call(SOAP_ACTION, envelope);
                SoapPrimitive result = (SoapPrimitive) envelope.getResponse();
                return result.toString();
            } catch (Exception e) {
                return e.getMessage();
            }
        }
    }

I call this class this way:

ConvertService service = new ConvertService();
String result = service.Convert("fabio", "123", 0);

But the following error occurs:

05-21 07:33:32.000    8834-8834/br.com.fjsa16.webservice E/AndroidRuntime﹕ FATAL EXCEPTION: main
    Process: br.com.fjsa16.webservice, PID: 8834
    java.lang.RuntimeException: Unable to start activity ComponentInfo{br.com.fjsa16.webservice/br.com.fjsa16.webservice.MainActivity}: java.lang.NullPointerException
            at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2195)
            at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2245)
            at android.app.ActivityThread.access$800(ActivityThread.java:135)
            at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1196)
            at android.os.Handler.dispatchMessage(Handler.java:102)
            at android.os.Looper.loop(Looper.java:136)
            at android.app.ActivityThread.main(ActivityThread.java:5017)
            at java.lang.reflect.Method.invokeNative(Native Method)
            at java.lang.reflect.Method.invoke(Method.java:515)
            at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:779)
            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595)
            at dalvik.system.NativeStart.main(Native Method)
     Caused by: java.lang.NullPointerException
            at com.android.internal.os.LoggingPrintStream.println(LoggingPrintStream.java:298)
            at br.com.fjsa16.webservice.MainActivity.onCreate(MainActivity.java:16)
            at android.app.Activity.performCreate(Activity.java:5231)
            at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)
            at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2159)
            at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2245)
            at android.app.ActivityThread.access$800(ActivityThread.java:135)
            at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1196)
            at android.os.Handler.dispatchMessage(Handler.java:102)
            at android.os.Looper.loop(Looper.java:136)
            at android.app.ActivityThread.main(ActivityThread.java:5017)
            at java.lang.reflect.Method.invokeNative(Native Method)
            at java.lang.reflect.Method.invoke(Method.java:515)
            at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:779)
            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595)
            at dalvik.system.NativeStart.main(Native Method)

It is the first time that I am consuming a webservice, so if there is something wrong in the codes please correct me.

Can someone help me?

  • 1

    Error appears in the method onCreate of Mainactivity. Post this method.

  • @Override&#xA; protected void onCreate(Bundle savedInstanceState) {&#xA; super.onCreate(savedInstanceState);&#xA; setContentView(R.layout.activity_main);&#xA;&#xA; ConvertService service = new ConvertService();&#xA; String result = service. Convert("Fabio", "123", 0); System.out.println(result); }

  • ramaral, a question: can tell me if the SOAP_ACTION, METHOD_NAME, NAMESPACE and URL strings are correct from this WSDL?

  • As for that I can not help. What I can say is that the error arises on the line System.out.println(result); because result is void.

  • Okay. Thank you ramaral.

  • Even if the result was null, this would not be the cause of the problem. in a conventional Java application, you would see "null" in the terminal. I suggest that instead of System.out, you use the code below to do this output on logcat: Log. i("Minhaapp", result);

  • Thanks Ucas... it worked.

Show 2 more comments
No answers

Browser other questions tagged

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