Unable to connect java webservie to android
- by nag prakash
This is my android activity.
Please help me out. I will send the project completely if you can drop your mail id.
package prakash.ws.connectsql;
import org.ksoap2.SoapEnvelope;
import org.ksoap2.serialization.SoapObject;
import org.ksoap2.serialization.SoapPrimitive;
import org.ksoap2.serialization.SoapSerializationEnvelope;
import org.ksoap2.transport.AndroidHttpTransport;
import android.os.Bundle;
import android.app.Activity;
import android.widget.EditText;
import android.widget.TextView;
public class MainActivity extends Activity {
private static final String Soap_Action="http://testws.ws.prakash/testws";
private static final String Method_Name="testws";
private static final String Name_Space="http://testws.ws.prakash/";
private static final String URI="http://localhost:8045/testws/services/Testws?wsdl";
EditText ET;
TextView Tv;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
// Packeting the request
SoapObject request=new SoapObject(Name_Space,Method_Name);
// pass the parameters to the method.If it has one
request.addProperty("name", ET.getText().toString());
//passing the entire request to the envelope
SoapSerializationEnvelope soapEnvelope=new SoapSerializationEnvelope(SoapEnvelope.VER11);
soapEnvelope.setOutputSoapObject(request);
//transporting envelope
AndroidHttpTransport aht=new AndroidHttpTransport(URI);
try{
aht.call(Soap_Action, soapEnvelope);
@SuppressWarnings("deprecation")
SoapPrimitive resultString=(SoapPrimitive) soapEnvelope.getResult();
Tv.setText(resultString.toString());
}catch(Exception e)
{
Tv.setText("error");
}
}
}
This XML file does not appear to have any style information associated with it. The document tree is shown below.
<wsdl:definitions xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns:ns1="http://org.apache.axis2/xsd" xmlns:ns="http://testws.ws.prakash" xmlns:wsaw="http://www.w3.org/2006/05/addressing/wsdl" xmlns:http="http://schemas.xmlsoap.org/wsdl/http/" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:mime="http://schemas.xmlsoap.org/wsdl/mime/" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:soap12="http://schemas.xmlsoap.org/wsdl/soap12/" targetNamespace="http://testws.ws.prakash">
<wsdl:documentation>Please Type your service description here</wsdl:documentation>
<wsdl:types>
<xs:schema attributeFormDefault="qualified" elementFormDefault="qualified" targetNamespace="http://testws.ws.prakash">
<xs:element name="testws">
<xs:complexType>
<xs:sequence>
<xs:element minOccurs="0" name="name" nillable="true" type="xs:string"/>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="testwsResponse">
<xs:complexType>
<xs:sequence>
<xs:element minOccurs="0" name="return" nillable="true" type="xs:string"/>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>
</wsdl:types>
<wsdl:message name="testwsRequest">
<wsdl:part name="parameters" element="ns:testws"/>
</wsdl:message>
<wsdl:message name="testwsResponse">
<wsdl:part name="parameters" element="ns:testwsResponse"/>
</wsdl:message>
<wsdl:portType name="TestwsPortType">
<wsdl:operation name="testws">
<wsdl:input message="ns:testwsRequest" wsaw:Action="urn:testws"/>
<wsdl:output message="ns:testwsResponse" wsaw:Action="urn:testwsResponse"/>
</wsdl:operation>
</wsdl:portType>
<wsdl:binding name="TestwsSoap11Binding" type="ns:TestwsPortType">
<soap:binding transport="http://schemas.xmlsoap.org/soap/http" style="document"/>
<wsdl:operation name="testws">
<soap:operation soapAction="urn:testws" style="document"/>
<wsdl:input>
<soap:body use="literal"/>
</wsdl:input>
<wsdl:output>
<soap:body use="literal"/>
</wsdl:output>
</wsdl:operation>
</wsdl:binding>
<wsdl:binding name="TestwsSoap12Binding" type="ns:TestwsPortType">
<soap12:binding transport="http://schemas.xmlsoap.org/soap/http" style="document"/>
<wsdl:operation name="testws">
<soap12:operation soapAction="urn:testws" style="document"/>
<wsdl:input>
<soap12:body use="literal"/>
</wsdl:input>
<wsdl:output>
<soap12:body use="literal"/>
</wsdl:output>
</wsdl:operation>
</wsdl:binding>
<wsdl:binding name="TestwsHttpBinding" type="ns:TestwsPortType">
<http:binding verb="POST"/>
<wsdl:operation name="testws">
<http:operation location="testws"/>
<wsdl:input>
<mime:content type="text/xml" part="parameters"/>
</wsdl:input>
<wsdl:output>
<mime:content type="text/xml" part="parameters"/>
</wsdl:output>
</wsdl:operation>
</wsdl:binding>
<wsdl:service name="Testws">
<wsdl:port name="TestwsHttpSoap11Endpoint" binding="ns:TestwsSoap11Binding">
<soap:address location="http://localhost:8045/testws/services/Testws.TestwsHttpSoap11Endpoint/"/>
</wsdl:port>
<wsdl:port name="TestwsHttpSoap12Endpoint" binding="ns:TestwsSoap12Binding">
<soap12:address location="http://localhost:8045/testws/services/Testws.TestwsHttpSoap12Endpoint/"/>
</wsdl:port>
<wsdl:port name="TestwsHttpEndpoint" binding="ns:TestwsHttpBinding">
<http:address location="http://localhost:8045/testws/services/Testws.TestwsHttpEndpoint/"/>
</wsdl:port>
</wsdl:service>
</wsdl:definitions>
this web service is running fine in the server.
Manifest File
I have added the internet Permission.
Now this is the error in the logcat.
07-04 21:31:00.757: E/dalvikvm(375): Could not find class 'org.ksoap2.serialization.SoapObject', referenced from method prakash.ws.connectsql.MainActivity.onCreate
07-04 21:31:00.757: W/dalvikvm(375): VFY: unable to resolve new-instance 481 (Lorg/ksoap2/serialization/SoapObject;) in Lprakash/ws/connectsql/MainActivity;
07-04 21:31:00.757: D/dalvikvm(375): VFY: replacing opcode 0x22 at 0x0008
07-04 21:31:00.757: D/dalvikvm(375): VFY: dead code 0x000a-004e in Lprakash/ws/connectsql/MainActivity;.onCreate (Landroid/os/Bundle;)V
07-04 21:31:00.937: D/AndroidRuntime(375): Shutting down VM
07-04 21:31:00.937: W/dalvikvm(375): threadid=1: thread exiting with uncaught exception (group=0x40015560)
07-04 21:31:00.957: E/AndroidRuntime(375): FATAL EXCEPTION: main
07-04 21:31:00.957: E/AndroidRuntime(375): java.lang.NoClassDefFoundError: org.ksoap2.serialization.SoapObject
07-04 21:31:00.957: E/AndroidRuntime(375): at prakash.ws.connectsql.MainActivity.onCreate(MainActivity.java:30)
07-04 21:31:00.957: E/AndroidRuntime(375): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
07-04 21:31:00.957: E/AndroidRuntime(375): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1611)
07-04 21:31:00.957: E/AndroidRuntime(375): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1663)
07-04 21:31:00.957: E/AndroidRuntime(375): at android.app.ActivityThread.access$1500(ActivityThread.java:117)
07-04 21:31:00.957: E/AndroidRuntime(375): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:931)
07-04 21:31:00.957: E/AndroidRuntime(375): at android.os.Handler.dispatchMessage(Handler.java:99)
07-04 21:31:00.957: E/AndroidRuntime(375): at android.os.Looper.loop(Looper.java:123)
07-04 21:31:00.957: E/AndroidRuntime(375): at android.app.ActivityThread.main(ActivityThread.java:3683)
07-04 21:31:00.957: E/AndroidRuntime(375): at java.lang.reflect.Method.invokeNative(Native Method)
07-04 21:31:00.957: E/AndroidRuntime(375): at java.lang.reflect.Method.invoke(Method.java:507)
07-04 21:31:00.957: E/AndroidRuntime(375): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
07-04 21:31:00.957: E/AndroidRuntime(375): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
07-04 21:31:00.957: E/AndroidRuntime(375): at dalvik.system.NativeStart.main(Native Method)
07-04 21:31:05.307: I/Process(375): Sending signal. PID: 375 SIG: 9