[英]How to use SOAP web service in android
I am using trying to integrate SOAP web service in android, i no enough idea about how soap web service work, after searching to internet i have integrated kSOAP lib in android studio and write this code 我正在尝试将SOAP Web服务集成到Android中,我对肥皂Web服务的工作方式还没有足够的了解,搜索到互联网后,我已经在android studio中集成了kSOAP lib并编写了此代码
public class SOAP extends AppCompatActivity {
String URL = "http://www.getrixi.com/GoTukxiWebServices/TukxiService.asmx";
String NAMESPACE = "http://tempuri.org/GetAssets";
String SOAP_ACTION = "http://tempuri.org/GetAssets";
String METHOD_NAME = "GetAssets";
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_soap);
Button bt_id = (Button) findViewById(R.id.bt_id);
bt_id.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
new CallWebService().execute();
}
});
}
class CallWebService extends AsyncTask<String, Void, String> {
@Override
protected void onPostExecute(String s) {
Log.e("TAG", "the result from server is: " + s);
}
@Override
protected String doInBackground(String... params) {
String result = "";
SoapObject soapObject = new SoapObject(NAMESPACE, METHOD_NAME);
soapObject.addProperty("Lat", "31.71");
soapObject.addProperty("Long", "74.34");
soapObject.addProperty("Radius", "30");
soapObject.addProperty("AssetType", "all");
/* PropertyInfo propertyInfo = new PropertyInfo();
propertyInfo.setName("Lat");
propertyInfo.setName("Long");
propertyInfo.setName("Radius");
propertyInfo.setName("AssetType");
propertyInfo.setValue(params[0]);
propertyInfo.setValue(params[1]);
propertyInfo.setValue(params[2]);
propertyInfo.setValue(params[3]);
propertyInfo.setType(String.class);
soapObject.addProperty(propertyInfo);*/
SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
envelope.setOutputSoapObject(soapObject);
HttpTransportSE httpTransportSE = new HttpTransportSE(URL);
try {
httpTransportSE.call(SOAP_ACTION, envelope);
SoapPrimitive soapPrimitive = (SoapPrimitive)envelope.getResponse();
Log.e("TAG", "the message result : " + soapPrimitive);
result = soapPrimitive.toString();
Log.e("TAG", "the resul is: " + result);
} catch (Exception e) {
e.printStackTrace();
}
return result;
}
}
how can i get json result i have test the api here http://getrixi.com/GoTukxiWebServices/TukxiService.asmx?op=GetAssets it is working fine on web with get method How can i get result in android 我如何获得json结果我已经在这里测试了api http://getrixi.com/GoTukxiWebServices/TukxiService.asmx?op=GetAssets使用get方法在网络上运行良好我如何在android中获得结果
This piece of code can be more illustrative : 这段代码可以更具说明性:
String str="http://your.domain.here/yourSubMethod";
URLConnection urlConn = null;
BufferedReader bufferedReader = null;
try
{
URL url = new URL(str);
urlConn = url.openConnection();
bufferedReader = new BufferedReader(new InputStreamReader(urlConn.getInputStream()));
StringBuffer stringBuffer = new StringBuffer();
String line;
while ((line = bufferedReader.readLine()) != null)
{
stringBuffer.append(line);
}
return new JSONObject(stringBuffer.toString());
}
catch(Exception ex)
{
Log.e("App", "yourDataTask", ex);
return null;
}
For details read Android: Fetching JSONARRAY Data from Web api 有关详细信息,请阅读Android: 从Web API获取JSONARRAY数据
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.