Click here to Skip to main content
15,881,204 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
Below are the code used to call .asmx websrvice from android application through ksop2
Manifest file

<manifest xmlns:android="http://schemas.android.com/apk/res/android">
package="com.attsystemsgroup.www.nithesh" >
<use-permission android:name="android.permission.INTERNET">
<use-permission android:name="android.permission.NETWORK">
<use-permission android:name="android.permission.ACCESS_NETWORK_STATE">
<use-permission android:name="android.permission.CHANGE_WIFI_MULTICAST_STATE">
<application>
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:supportsRtl="true"
android:theme="@style/AppTheme" >
<activity>
android:name=".MainActivity"
android:label="@string/app_name"
android:theme="@style/AppTheme.NoActionBar" >
<intent-filter>
<action android:name="android.intent.action.MAIN">

<category android:name="android.intent.category.LAUNCHER">








package com.attsystemsgroup.www.nithesh;

import android.os.Bundle;
import android.support.design.widget.FloatingActionButton;
import android.support.design.widget.Snackbar;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.view.View;
import android.view.Menu;
import android.view.MenuItem;
import android.widget.TextView;

public class MainActivity extends AppCompatActivity {
public String val="";
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);

FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab);
fab.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
// this.textView2.setText("");
Snackbar.make(view, "Replace with your own action", Snackbar.LENGTH_LONG)
.setAction("Action", null).show();
}
});
}
public void onButtonClick(View view){
// string val="";
CallSoap ca=new CallSoap();
val=ca.Call();
TextView textView =
(TextView)findViewById(R.id.textView);
textView.setText(val);
//do something when button is clicked.

}
@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);
}
}


package com.attsystemsgroup.www.nithesh;

import org.ksoap2.SoapEnvelope;
import org.ksoap2.serialization.PropertyInfo;
import org.ksoap2.serialization.SoapObject;
import org.ksoap2.serialization.SoapSerializationEnvelope;
import org.ksoap2.transport.HttpTransportSE;
/**
* Created by ATTS on 20/11/2015.
*/
public class CallSoap {
public final String SOAP_ACTION = "http://tempuri.org/HelloWorld";

public final String OPERATION_NAME = "HelloWorld";

public final String WSDL_TARGET_NAMESPACE = "http://tempuri.org/";

public final String SOAP_ADDRESS = "http://101.100.166.110:8075/service1.asmx";
public CallSoap()
{
}
public String Call()
{
SoapObject request = new SoapObject(WSDL_TARGET_NAMESPACE,OPERATION_NAME);
// PropertyInfo pi=new PropertyInfo();
//pi.setName("a");
//pi.setValue(a);
//pi.setType(Integer.class);
//request.addProperty(pi);
//pi=new PropertyInfo();
//pi.setName("b");
//pi.setValue(b);
//pi.setType(Integer.class);
//request.addProperty(pi);

SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(
SoapEnvelope.VER11);
envelope.dotNet = true;

envelope.setOutputSoapObject(request);

HttpTransportSE httpTransport = new HttpTransportSE(SOAP_ADDRESS);
Object response=null;
try
{
httpTransport.call(SOAP_ACTION, envelope);
response = envelope.getResponse();
}
catch (Exception exception)
{
response=exception.toString();
}
return response.toString();
}

}
Posted
Comments
Richard MacCutchan 23-Nov-15 9:11am    
Where does the exception occur, and what other information is in the exception?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900