Android寮€鍙戣皟鐢╳ebservice鏂瑰紡涔嬩竴
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Android寮€鍙戣皟鐢╳ebservice鏂瑰紡涔嬩竴相关的知识,希望对你有一定的参考价值。
鏍囩锛?a href='http://www.mamicode.com/so/1/gets' title='gets'>gets
init method deb timeout manage style ssim http娣诲姞ksoap2-android-assembly-3.6.3-jar-with-dependencies.jar鍖?/pre>鍒涘缓KsoapHelper绫?public class KsoapHelper {
public static int timeOut = 30000;
public static String webServiceUrl;
public static String nameSpace;
public static int soapVersion = 120;
private KsoapHelper() {
}
public static void initKsoapHelper(String _webServiceUrl, String _nameSpace) {
initKsoapHelper(timeOut, _webServiceUrl, _nameSpace, soapVersion);
}
public static void initKsoapHelper(String _webServiceUrl, String _nameSpace, int _version) {
initKsoapHelper(timeOut, _webServiceUrl, _nameSpace, _version);
}
public static void initKsoapHelper(int _timeOut, String _webServiceUrl, String _nameSpace, int _version) {
nameSpace = _nameSpace;
webServiceUrl = _webServiceUrl;
timeOut = _timeOut;
soapVersion = _version;
}
public static SoapObject GetSoapObject(String methodName) {
SoapObject object = new SoapObject(nameSpace, methodName);
return object;
}
public static SoapObject GetSoapObject(String nameSpace, String methodName) {
SoapObject object = new SoapObject(nameSpace, methodName);
return object;
}
public static Object GetResult(SoapObject object, boolean isSimple) throws IOException, XmlPullParserException {
SoapSerializationEnvelope sSEnvelope = new SoapSerializationEnvelope(120);
sSEnvelope.bodyOut = object;
sSEnvelope.dotNet = true;
HttpTransportSE httpTransSE = new HttpTransportSE(webServiceUrl, timeOut);
httpTransSE.debug = true;
httpTransSE.call((String)null, sSEnvelope);
SoapObject result;
if (isSimple) {
result = null;
Object simpleResult = sSEnvelope.getResponse();
return simpleResult.toString();
} else {
result = null;
result = (SoapObject)sSEnvelope.getResponse();
SoapObject childs = (SoapObject)result.getProperty(1);
return (SoapObject)childs.getProperty(0);
}
}
}缂栧啓MainActivity绫伙紝姗欒壊閮ㄥ垎鏍规嵁鑷繁鎯呭喌鏇存敼public class MainActivity extends AppCompatActivity implements View.OnClickListener {
private String WEBSERVICE_URL;
private String NAMESPACE;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
initView();
}
/**
* 鍒濆鍖?br /> */
private void initView() {
WEBSERVICE_URL = "http://192.168.200.185:8090/UserInfoManagement.asmx?wsdl";
NAMESPACE = "http://tempuri.org/";
}
@Override
public void onClick(View view) {
switch (view.getId()){
case R.id.btn_enter:
Login();
break;
}
}
銆€銆€ public void Login(){
KsoapHelper.initKsoapHelper(WEBSERVICE_URL, NAMESPACE);
SoapObject request = KsoapHelper.GetSoapObject("UserCheck");
request.addProperty("UserID", et_name.getText().toString());
request.addProperty("Password", et_pwd.getText().toString());
try {
String sCheckuser=(String) KsoapHelper.GetResult(request, true);
} catch (Exception var) {
return ;
}
}
}
以上是关于Android寮€鍙戣皟鐢╳ebservice鏂瑰紡涔嬩竴的主要内容,如果未能解决你的问题,请参考以下文章
浜笢鎺ㄥ嚭杞婚噺绾у垎甯冨紡 RPC 妗嗘灦 鈥?EasyRPC
2020-2021骞翠箣闂?65+寮€鍙戣祫婧愭暣鐞?/a>