Calling SOAP Service

Put your problem here if it does not fit any of the other categories.

Calling SOAP Service

Postby Matimuh » Tue Jul 03, 2012 2:51 pm

hey i have made this program that should call a webservice

my the program crash when i click
Can you help me find the problem...

Code: Select all
package com.webserivce;

import org.ksoap2.SoapEnvelope;
import org.ksoap2.serialization.SoapObject;
import org.ksoap2.serialization.SoapSerializationEnvelope;
import org.ksoap2.transport.HttpTransportSE;
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;

public class WebServiceDemoActivity extends Activity
{
    /** Called when the activity is first created. */
      private static String SOAP_ACTION1 = "http://www.webserviceX.NET/GetQuote";
      private static String NAMESPACE = "http://www.webserviceX.NET";
      private static String METHOD_NAME1 = "GetQuote";
      private static String URL = "http://www.webservicex.net/stockquote.asmx?WSDL";

      Button btnFar,btnClear;
      EditText txtFar,txtCel;
     
    @Override
    public void onCreate(Bundle savedInstanceState)
    {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
       
        btnFar = (Button)findViewById(R.id.btnFar);
        btnClear = (Button)findViewById(R.id.btnClear);
        txtFar = (EditText)findViewById(R.id.txtFar);
        txtCel = (EditText)findViewById(R.id.txtCel);
       
        btnFar.setOnClickListener(new View.OnClickListener()
        {
                  @Override
                  public void onClick(View v)
                  {
                        //Initialize soap request + add parameters
                  SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME1);       
                 
                  //Use this to add parameters
                  //request.addProperty("symbol",txtFar.getText().toString());
                 
                  //Declare the version of the SOAP request
                  SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
                 
                  envelope.setOutputSoapObject(request);
                  envelope.dotNet = true;
                 
                  try {
                        HttpTransportSE androidHttpTransport = new HttpTransportSE(URL);
                       
                        //this is the actual part that will call the webservice
                        androidHttpTransport.call(SOAP_ACTION1, envelope);
                       
                        // Get the SoapResult from the envelope body.
                        SoapObject result = (SoapObject)envelope.bodyIn;

                        if(result != null)
                        {
                              //Get the first property and change the label text
                              txtCel.setText(result.getProperty(0).toString());
                        }
                        else
                        {
                              Toast.makeText(getApplicationContext(), "No Response",Toast.LENGTH_LONG).show();
                        }
                  } catch (Exception e) {
                        e.printStackTrace();
                  }
                  }
            });
       
        btnClear.setOnClickListener(new View.OnClickListener()
        {
                  @Override
                  public void onClick(View v)
                  {
                        txtCel.setText("");
                        txtFar.setText("");
                  }
            });
    }
}
Matimuh
Once Poster
Once Poster
 
Posts: 1
Joined: Tue Jul 03, 2012 2:48 pm

Top

Re: Calling SOAP Service

Postby rodrigobraz » Mon Mar 04, 2013 9:33 pm

Above Android 3.0 you can not do Http requests on main thread!

Try "AsyncTask".
http://developer.android.com/reference/ ... cTask.html

don't forget (AndroidManifest.xml):
<uses-permission android:name="android.permission.INTERNET" >
User avatar
rodrigobraz
Once Poster
Once Poster
 
Posts: 1
Joined: Mon Mar 04, 2013 9:07 pm

Re: Calling SOAP Service

Postby christusvalerian » Thu Mar 21, 2013 10:45 am

You need to use Ksoap for consuming soap webservice,Here is link with sample

https://code.google.com/p/ksoap2-android/

Regards
Android developer
Trinay Technology Solutions
http://www.trinaytech.com
5705750475
christusvalerian
Developer
Developer
 
Posts: 28
Joined: Sat Jun 18, 2011 8:03 am

Top

Return to Other Coding-Problems

Who is online

Users browsing this forum: Exabot [Bot] and 11 guests