envelope.dotNet = true
fixed the problem for me. Thank you.



Lex wrote:Hi,
Im trying to receive data from a Web Service. I'm using KSOAP2. Here's my codeUsing java Syntax Highlighting
package com.google.android.Test; import org.ksoap2.SoapEnvelope; import org.ksoap2.serialization.SoapObject; import org.ksoap2.serialization.SoapSerializationEnvelope; import org.ksoap2.transport.HttpTransport; import android.app.Activity; import android.os.Bundle; import android.widget.TextView; public class myWebService extends Activity { private static final String SOAP_ACTION = "HelloYou"; private static final String METHOD_NAME = "getHello"; private static final String NAMESPACE = "urn:HelloYou"; private static final String URL = "http://localhost/lab/service.php"; private Object resultRequestSOAP = null; @Override public void onCreate(Bundle icicle) { super.onCreate(icicle); TextView tv = new TextView(this); setContentView(tv); SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME); //SoapObject request.addProperty("firstname", "John"); request.addProperty("lastname", "Williams"); SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11); envelope.setOutputSoapObject(request); HttpTransport androidHttpTransport = new HttpTransport(URL); try { androidHttpTransport.call(SOAP_ACTION, envelope); resultsRequestSOAP = envelope.getResponse(); String[] results = (String[]) resultsRequestSOAP; tv.setText( results[0]); } catch (Exception aE) { aE.printStackTrace ();; } } }Parsed in 0.037 seconds, using GeSHi 1.0.8.4
I'm getting an Error because the IO/Connector is missing ? Is there any other way to retrieve data from a webservice then ?






junejar wrote:Hi
I am not able to run a very basic client programme using ksoap. Code posted below. Application force closes. On debug, this line is the culprit androidHttpTransport.call(
Any help appreciated.
import org.ksoap2.SoapEnvelope;
import org.ksoap2.serialization.SoapObject;
import org.ksoap2.serialization.SoapSerializationEnvelope;
import org.ksoap2.transport.AndroidHttpTransport;
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.TextView;
public class Sample extends Activity {
private static final String SOAP_ACTION = "getCurrentPosition";
private static final String METHOD_NAME = "getCurrentPosition";
private static final String NAMESPACE = "";
private static final String URL = "http://192.168.56.1:8080/axis/NHLService.jws";
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
findViewById(R.id.cmdCalculate).setOnClickListener(new OnClickListener() {
public void onClick(View view) {
((TextView)findViewById(R.id.lblStatus)).setText("... Invoking Web Service ...");
String a = "central";
String b = "chicago";
SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME);
request.addProperty("division", a);
request.addProperty("team", b);
SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
envelope.setOutputSoapObject(request);
AndroidHttpTransport androidHttpTransport = new AndroidHttpTransport (URL);
try {
androidHttpTransport.call(SOAP_ACTION, envelope);
Object result = envelope.getResponse();
((TextView)findViewById(R.id.lblStatus)).setText(result.toString());
} catch(Exception e) {
e.printStackTrace();
}
} // on click ends
});//listner ends
}//on create ends
}//end


Lex wrote:Hi,
Im trying to receive data from a Web Service. I'm using KSOAP2. Here's my codeUsing java Syntax Highlighting
package com.google.android.Test; import org.ksoap2.SoapEnvelope; import org.ksoap2.serialization.SoapObject; import org.ksoap2.serialization.SoapSerializationEnvelope; import org.ksoap2.transport.HttpTransport; import android.app.Activity; import android.os.Bundle; import android.widget.TextView; public class myWebService extends Activity { private static final String SOAP_ACTION = "HelloYou"; private static final String METHOD_NAME = "getHello"; private static final String NAMESPACE = "urn:HelloYou"; private static final String URL = "http://localhost/lab/service.php"; private Object resultRequestSOAP = null; @Override public void onCreate(Bundle icicle) { super.onCreate(icicle); TextView tv = new TextView(this); setContentView(tv); SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME); //SoapObject request.addProperty("firstname", "John"); request.addProperty("lastname", "Williams"); SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11); envelope.setOutputSoapObject(request); HttpTransport androidHttpTransport = new HttpTransport(URL); try { androidHttpTransport.call(SOAP_ACTION, envelope); resultsRequestSOAP = envelope.getResponse(); String[] results = (String[]) resultsRequestSOAP; tv.setText( results[0]); } catch (Exception aE) { aE.printStackTrace ();; } } }Parsed in 0.042 seconds, using GeSHi 1.0.8.4
I'm getting an Error because the IO/Connector is missing ? Is there any other way to retrieve data from a webservice then ?


Cybermat wrote:Hi Lex, not sure if you were able to solve your problem, but I ran into the same issue and I was able to solve it using the following method. I hope it solves your issue. If not, let me know and post your SOAP return in XML format. So that it would be easier for us to troubleshoot.
HttpTransport androidHttpTransport = new HttpTransport(URL);
try
{
androidHttpTransport.call(SOAP_ACTION, envelope);
SoapObject resultsRequestSOAP = (SoapObject) envelope.bodyIn;
Vector XXXX = (Vector) resultsRequestSOAP.getProperty("[Data element name]");
Just treat the Vector as a normal Java vector, then you should be able to pull all your data
element out
}
catch (Exception aE)
{
aE.printStackTrace ();;
}
}


netmercury wrote:I have the same problem as well!!!!
I have set up the webservice with java and deployed into tomcat.
I am using ksoap2 as webservice client in my app.
Couldn't cast the develope.getResponse() into any type....
Anyone has solution?
Thank you.



Return to Other Coding-Problems
Users browsing this forum: No registered users and 8 guests