Webservice from Android
FirstAppUI.java class
Insert
Insert Internet access permission to your mobile application in AndroidManifest.xml file as:
ServiceImpl.wsdl:
package com.test.android;
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.widget.ArrayAdapter;
import android.widget.AutoCompleteTextView;
public class FirstAppUI extends Activity {
private static final String NAMESPACE = "com.service.ServiceImpl";
private static final String URL =
"http://192.168.202.124:9000/AndroidWS/wsdl/ServiceImpl.wsdl";
private static final String SOAP_ACTION = "ServiceImpl";
private static final String METHOD_NAME = "message";
private static final String[] sampleACTV = new String[] {
"android", "iphone", "blackberry"
};
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
ArrayAdapter<String> arrAdapter = new ArrayAdapter<String>
(this, android.R.layout.simple_dropdown_item_1line, sampleACTV);
AutoCompleteTextView ACTV = (AutoCompleteTextView)findViewById
(R.id.AutoCompleteTextView01);
ACTV.setAdapter(arrAdapter);
SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME);
SoapSerializationEnvelope envelope =
new SoapSerializationEnvelope(SoapEnvelope.VER11);
envelope.setOutputSoapObject(request);
HttpTransportSE androidHttpTransport = new HttpTransportSE(URL);
try {
androidHttpTransport.call(SOAP_ACTION, envelope);
SoapObject resultsRequestSOAP = (SoapObject) envelope.bodyIn;
ACTV.setHint("Received :" + resultsRequestSOAP.toString());
} catch (Exception e) {
e.printStackTrace();
}
}
}
AutoCompleteTextView
to your res>layout >main.xml as:<?xml version="1.0" encoding="utf-8"?>
<LinearLayout android:id="@+id/LinearLayout01"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
xmlns:android="http://schemas.android.com/apk/res/android">
<AutoCompleteTextView
android:id="@+id/AutoCompleteTextView01"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:hint="This is Hint"
android:width="240px" />
</LinearLayout>
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.test.android"
android:versionCode="1"
android:versionName="1.0">
<application android:icon="@drawable/icon" android:label="@string/app_name">
<activity android:name=".FirstAppUI"
android:label="@string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
<uses-permission android:name="android.permission.INTERNET"></uses-permission>
<uses-sdk android:minSdkVersion="8" />
</manifest>
<?xml version="1.0" encoding="UTF-8"?>
<wsdl:definitions targetNamespace=http://service.com
xmlns:apachesoap=http://xml.apache.org/xml-soap
xmlns:impl="http://service.com" xmlns:intf=http://service.com
xmlns:wsdl=http://schemas.xmlsoap.org/wsdl/
xmlns:wsdlsoap=http://schemas.xmlsoap.org/wsdl/soap/
xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<!--WSDL created by Apache Axis version: 1.4
Built on Apr 22, 2006 (06:55:48 PDT)-->
<wsdl:types>
<schema elementFormDefault="qualified"
targetNamespace="http://service.com" xmlns="http://www.w3.org/2001/XMLSchema">
<element name="message">
<complexType/>
</element>
<element name="messageResponse">
<complexType>
<sequence>
<element name="messageReturn" type="xsd:string"/>
</sequence>
</complexType>
</element>
</schema>
</wsdl:types>
<wsdl:message name="messageResponse">
<wsdl:part element="impl:messageResponse" name="parameters">
</wsdl:part>
</wsdl:message>
<wsdl:message name="messageRequest">
<wsdl:part element="impl:message" name="parameters">
</wsdl:part>
</wsdl:message>
<wsdl:portType name="ServiceImpl">
<wsdl:operation name="message">
<wsdl:input message="impl:messageRequest" name="messageRequest">
</wsdl:input>
<wsdl:output message="impl:messageResponse" name="messageResponse">
</wsdl:output>
</wsdl:operation>
</wsdl:portType>
<wsdl:binding name="ServiceImplSoapBinding" type="impl:ServiceImpl">
<wsdlsoap:binding style="document"
transport="http://schemas.xmlsoap.org/soap/http"/>
<wsdl:operation name="message">
<wsdlsoap:operation soapAction=""/>
<wsdl:input name="messageRequest">
<wsdlsoap:body use="literal"/>
</wsdl:input>
<wsdl:output name="messageResponse">
<wsdlsoap:body use="literal"/>
</wsdl:output>
</wsdl:operation>
</wsdl:binding>
<wsdl:service name="ServiceImplService">
<wsdl:port binding="impl:ServiceImplSoapBinding" name="ServiceImpl">
<wsdlsoap:address location=
"http://localhost:9000/AndroidWS/services/ServiceImpl"/>
</wsdl:port>
</wsdl:service>
</wsdl:definitions>
Comments
Post a Comment
Please post comments here:-)