/ / Namespace
String nameSpace = "http://tempuri.org/";
/ / Method name
callString methodName = "Getlist";
/ / EndPoint
String endPoint = "http://10.141.37.197/yy/AndroidService.asmx";
/ / SOAP Action
String soapAction = "http://tempuri.org/Getlist";
/ / Specify WebService namespace and method name to call
SoapObject rpc = new SoapObject (nameSpace, methodName);
/ / Set the required incoming call WebService interface requires two parameters mobileCode, userId
rpc.addProperty ("id", phoneSec);
/ / Rpc.addProperty ("userId", "");
/ / Generate method call WebService SOAP request message, and specify the version of SOAP
SoapSerializationEnvelope envelope = new SoapSerializationEnvelope (
SoapEnvelope.VER10);
envelope.bodyOut = rpc;
/ / Set whether the call is. Net development WebService
envelope.dotNet = true ;/ / / / webservice specified type (java, PHP, dotNet)
/ / equivalent to envelope.bodyOut = rpc;
envelope.setOutputSoapObject (rpc);
HttpTransportSE transport = new HttpTransportSE (endPoint);
try {
/ / Call WebService
transport.call (soapAction, envelope);
} Catch (Exception e) {
e.printStackTrace ();
}
/ / Get the returned data
SoapObject object = (SoapObject) envelope.bodyIn ;/ / error here, a direct jump out because webservice client returns a dateset / / Get Return results
String result = object.getProperty (0) toString ();.
/ / Display the results returned by WebService in TextView in
textView.setText (result);
Reply:
This is the type of return, make up, how to resolve it?
Reply:
Do not sink ah, 555555555555
Reply:
Recently, too anxious to do it, you marching help
Reply:
Can not resolve it yourself?
Reply:
You all know that the return type is DataSet, and how still use SoapObject and (SoapObject) do convert it?
Use DataSet treatment should be all right.
Reply:
Xml parsing can not directly get the element sequence under
Reply:
You use system.out.println (object.toString ()) look, your screenshot looks like a WebService method provides not return data.
I here call returns the following data:
06-18 17:57:04.730: I / System.out (29365): anyType {item = N / A; item = 5703918.7; item = 227986;}
Reply:
Another tragedy webservice communication with donet android platform
Two solutions:
1, so that the webservice return donet platform standard xml object. Then get android side parsing XML tree JAVA objects.
2, android terminal directly parse tree assembled JAVA DataSet object.
Another: Get return results, please use: envelope.getResponse ();
Reply:
Finally, put the data they used are taken out,
/ / Use Map to represent tabular data
Map
flags = object.getProperty (0) toString ();.
Pattern pattern = Pattern.compile ("ds = anyType \ \ {[^}] * \ \};");
Matcher m = pattern.matcher (flags) ;/ / import java.util.regex.Matcher;
while (m.find ())
{
String tmp = m.group () replace ("ds = anyType {", "");.
String [] Strlen = tmp.split (";");
if (Strlen.length> 1)
{
mapOne = new HashMap
. String khbh = Strlen [0] split ("=") [1];
. String khqc = Strlen [1] split ("=") [1];
mapOne.put ("user_name", khbh);
mapOne.put ("user_pasword", khqc) ;/ / map keys are not allowed to repeat, otherwise the previous value will be overwritten
list.add (mapOne);
}
}
Reply:
Also encountered a big problem, I have Android 2.2 phones can access the network, but the development of software version 4.0 or higher installed directly error (4.0 after the main thread can not access the network), the online approach seems to not work, If you want to change, and that the above code on how to change it?
Reply:
1 mistake that step should be written like this:
if (envelope.getResponse ()! = null) {
return parse (envelope.bodyIn.toString ());
}
/ **************
* Parse XML
* @ Param str
* @ Return
* /
private static List
String temp;
List
if (str! = null && str.length ()> 0) {
int start = str.indexOf ("string");
int end = str.lastIndexOf (";");
temp = str.substring (start, end-3);
String [] test = temp.split (";");
for (int i = 0; i
temp = test [i] substring (7);.
} Else {
temp = test [i] substring (8);.
}
int index = temp.indexOf (",");
list.add (temp.substring (0, index));
}
}
return list;
}
2 colon is xml namespace, self Baidu: xml parsing namespace lookup
3.4.0 After the main thread can not access the network, which is strict mode, StrictMode class. Baidu own strict mode
Reply:
package test.webservice;
import org.ksoap2.SoapEnvelope;
import org.ksoap2.serialization.SoapObject;
import org.ksoap2.serialization.SoapSerializationEnvelope;
import org.ksoap2.transport.HttpTransportSE;
import test.webservice.R;
import android.os.Bundle;
import android.os.Handler;
import android.os.StrictMode;
import android.os.AsyncTask;
import android.app.Activity;
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.content.Intent;
import android.view.KeyEvent;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.AdapterView;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.ListView;
import android.os.PatternMatcher;
import java.util.Iterator;
import java.util.Set;
import java.util.List;
import android.app.ListActivity;
import android.graphics.Color;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;
import java.util.regex.Pattern;
import java.util.regex.Matcher;
import android.widget.SimpleAdapter;
import android.widget.AdapterView.OnItemClickListener;
import android.net.NetworkInfo;
import android.os.Build.VERSION;
public class kehu extends Activity {
EditText editText1;
TextView textView1;
Button button1;
ListView lv;
ArrayList
No comments:
Post a Comment