如何解析来自服务器对象来的SOAP网络服务? [英] How to parse the soap web service coming from server object?
本文介绍了如何解析来自服务器对象来的SOAP网络服务?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我能够从服务器响应,而这样做的肥皂programming.My问题是从服务器上我得到的对象,现在我需要从服务器的响应值。这里是我的code和响应
包com.example.networkconnectivity;进口org.ksoap2.SoapEnvelope;
进口org.ksoap2.SoapFault;
进口org.ksoap2.serialization.PropertyInfo;
进口org.ksoap2.serialization.SoapObject;
进口org.ksoap2.serialization.SoapPrimitive;
进口org.ksoap2.serialization.SoapSerializationEnvelope;
进口org.ksoap2.transport.AndroidHttpTransport;进口android.app.Activity;
进口android.app.ProgressDialog;
进口android.content.Context;
进口android.net.ConnectivityManager;
进口android.net.NetworkInfo;
进口android.os.AsyncTask;
进口android.os.Bundle;
进口android.util.Log;
进口android.widget.ArrayAdapter;
进口android.widget.AutoCompleteTextView;
进口android.widget.Toast;公共类MainActivity延伸活动{
AutoCompleteTextView autocompletetextview; String []数组= {一,二,三,四有,五,六,七宗罪,
八,九,十大};
私有静态最后弦乐SOAP_ACTION =http://wsendpoints.bbrailapps.firstgroup.com/getDestinationStationDashboard;
私有静态最后弦乐METHOD_NAME =getDestinationStationDashboard;
私有静态最后弦乐NAMESPACE =http://wsendpoints.bbrailapps.firstgroup.com;
私有静态最终字符串URL =http://railapps.firstgroup.com/FirstGroupRailApps/services/RailAppsCAWS?wsdl;
私人SoapObject resultRequestSOAP = NULL; @覆盖
保护无效的onCreate(捆绑savedInstanceState){
super.onCreate(savedInstanceState);
的setContentView(R.layout.activity_main);
autocompletetextview =(AutoCompleteTextView)findViewById(R.id.autocompletetextview); ArrayAdapter<串GT;适配器=新ArrayAdapter<串GT;(这一点,
android.R.layout.select_dialog_item,数组); autocompletetextview.setThreshold(2); autocompletetextview.setAdapter(适配器);
的System.out.println(=====================+ haveNetworkConnection()); 新的AsyncTask<太虚,太虚,对象>(){
ProgressDialog对话框=新ProgressDialog(MainActivity.this);
私人的PropertyInfo PI1;
私人字符串健胃presult; 在preExecute保护无效(){
dialog.show();
}; 保护对象doInBackground(无效[] PARAMS){ / * resultRequestSOAP =新SoapObject空间(namespace,METHOD_NAME); SoapSerializationEnvelope envp =新SoapSerializationEnvelope(
SoapEnvelope.VER11);
envp.dotNet = TRUE;
envp.setOutputSoapObject(resultRequestSOAP);
AndroidHttpTransport androidHttpTransport =新AndroidHttpTransport(
URL);
尝试{
androidHttpTransport.call(SOAP_ACTION,envp);
SoapPrimitive resultsString =(SoapPrimitive)envp.getResponse();
的System.out.println(resultsString+ resultsString);
返回resultsString.toString(); }赶上(例外五){
的System.out.println(---------------------------+ e.toString());
Log.d(PPP,e.toString());
Toast.makeText(Soapclass.this,
检查网络connectivety+ e.toString()
Toast.LENGTH_LONG).show();
Log.v(WS错误 - >中,e.toString());
返回e.toString();
} * / resultRequestSOAP =新SoapObject空间(namespace,METHOD_NAME);
PI1 =新的PropertyInfo();
pi1.setName(CRS code);
pi1.setValue(HNH); //获取要被发送到web服务的串
pi1.setType(为String.class);
resultRequestSOAP.addProperty(PI1);
SoapSerializationEnvelope envp =新SoapSerializationEnvelope(
SoapEnvelope.VER11);
envp.dotNet = TRUE;
envp.setOutputSoapObject(resultRequestSOAP);
AndroidHttpTransport androidHttpTransport =新AndroidHttpTransport(
URL);
尝试{
androidHttpTransport.call(SOAP_ACTION,envp);
如果(envp.bodyIn的instanceof的SOAPFault){
SOA presult =((的SOAPFault)envp.bodyIn).faultstring;
的System.out.println(==健胃presulght ===+健胃presult);
}其他{
SoapObject resultsRequestSOAP =(SoapObject)envp.bodyIn;
SOA presult = resultsRequestSOAP.getProperty(0)的ToString();
的System.out.println(==健胃presult ===+健胃presult);
}
// SoapObject OBJ =(SoapObject)envp.getResponse();
//
//的System.out.println(resultsString+ OBJ);
返回健胃presult; }赶上(例外五){
的System.out.println(---------------------------+ e.toString());
Log.d(PPP,e.toString());
Toast.makeText(MainActivity.this,
检查网络connectivety+ e.toString()
Toast.LENGTH_LONG).show();
Log.v(WS错误 - >中,e.toString());
返回e.toString();
}
}; 保护无效onPostExecute(对象结果){
dialog.dismiss();
Toast.makeText(MainActivity.this,
检查网络connectivety+结果,
Toast.LENGTH_LONG).show();
};
}。执行(); } 公共布尔haveNetworkConnection(){
布尔haveConnectedWifi = FALSE;
布尔haveConnectedMobile = FALSE; ConnectivityManager厘米=(ConnectivityManager)getSystemService(Context.CONNECTIVITY_SERVICE);
的NetworkInfo [] = NetInfo的cm.getAllNetworkInfo();
对于(NI的NetworkInfo:NetInfo的){
如果(ni.getTypeName()。equalsIgnoreCase(WIFI))
如果(ni.isConnected())
haveConnectedWifi = TRUE;
如果(ni.getTypeName()。equalsIgnoreCase(手机))
如果(ni.isConnected())
haveConnectedMobile = TRUE;
}
返回haveConnectedWifi || haveConnectedMobile;
}}
的System.out.println(==健胃presult ===+健胃presult);
响应
{anyType的RID = 201309201377831; alertDetailPopulated = FALSE; alertsId = 0; alertsSummary = NULL; destExpArrival = 08:01; destSchArrival = 08:00; destinationStation = {anyType的CRS code = BKJ;工作站名称=贝克汉姆交叉口; }; expArrival = 07:49; expDepart = 07:49; otherAlert present = FALSE; platformNo = 3; routeDetailPopulated = FALSE; routeDetails = NULL; RSID = NULL; schArrival = 07:49; schDepart = 07:49; serviceAlert present = FALSE; TOC = SE; tocName =东南部; trainID = 2M18; trainLastReportedAt = NULL; }
现在我想打印的 RID 和 alertDetailPopulated 的值。
解决方案
@覆盖
保护SoapObject doInBackground(字符串... PARAMS){
// TODO自动生成方法存根
意向I = getIntent();
字符串= i.getStringExtra(code);
CallSoap CS =新CallSoap();
RESP = cs.Call(一);
的System.out.println(ssssssssssssssssssssssssssssssssss+ RESP);
返回RESP;
}
保护无效onPostExecute(对象结果){
如果(结果!= NULL)
{
的String [] = testValues新的String [result.getPropertyCount()];
对于(INT J = 0; J< result.getPropertyCount(); J ++){
testValues [J] = result.getProperty(J)的ToString();
字符串名称=(result.getProperty(0)的ToString()); Toast.makeText(MainActivity.this,
检查网络connectivety+名
Toast.LENGTH_LONG).show();
};
I am able to get response from server while doing soap programming.My problem is the I am getting object from the server,Now I need to get values from server response .Here is my code and response
package com.example.networkconnectivity;
import org.ksoap2.SoapEnvelope;
import org.ksoap2.SoapFault;
import org.ksoap2.serialization.PropertyInfo;
import org.ksoap2.serialization.SoapObject;
import org.ksoap2.serialization.SoapPrimitive;
import org.ksoap2.serialization.SoapSerializationEnvelope;
import org.ksoap2.transport.AndroidHttpTransport;
import android.app.Activity;
import android.app.ProgressDialog;
import android.content.Context;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;
import android.os.AsyncTask;
import android.os.Bundle;
import android.util.Log;
import android.widget.ArrayAdapter;
import android.widget.AutoCompleteTextView;
import android.widget.Toast;
public class MainActivity extends Activity {
AutoCompleteTextView autocompletetextview;
String[] array = { "One", "Two", "Three", "Four", "Five", "Six", "Seven",
"Eight", "Nine", "Ten" };
private static final String SOAP_ACTION = "http://wsendpoints.bbrailapps.firstgroup.com/getDestinationStationDashboard";
private static final String METHOD_NAME = "getDestinationStationDashboard";
private static final String NAMESPACE = "http://wsendpoints.bbrailapps.firstgroup.com";
private static final String URL = "http://railapps.firstgroup.com/FirstGroupRailApps/services/RailAppsCAWS?wsdl";
private SoapObject resultRequestSOAP = null;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
autocompletetextview = (AutoCompleteTextView) findViewById(R.id.autocompletetextview);
ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,
android.R.layout.select_dialog_item, array);
autocompletetextview.setThreshold(2);
autocompletetextview.setAdapter(adapter);
System.out.println("=====================" + haveNetworkConnection());
new AsyncTask<Void, Void, Object>() {
ProgressDialog dialog = new ProgressDialog(MainActivity.this);
private PropertyInfo pi1;
private String SoapResult;
protected void onPreExecute() {
dialog.show();
};
protected Object doInBackground(Void[] params) {
/*resultRequestSOAP = new SoapObject(NAMESPACE, METHOD_NAME);
SoapSerializationEnvelope envp = new SoapSerializationEnvelope(
SoapEnvelope.VER11);
envp.dotNet = true;
envp.setOutputSoapObject(resultRequestSOAP);
AndroidHttpTransport androidHttpTransport = new AndroidHttpTransport(
URL);
try {
androidHttpTransport.call(SOAP_ACTION, envp);
SoapPrimitive resultsString = (SoapPrimitive)envp.getResponse();
System.out.println("resultsString"+resultsString);
return resultsString.toString();
} catch (Exception e) {
System.out.println("---------------------------"+e.toString());
Log.d("ppp", e.toString());
Toast.makeText(Soapclass.this,
"Check Network connectivety" + e.toString(),
Toast.LENGTH_LONG).show();
Log.v("WS Error->", e.toString());
return e.toString();
}*/
resultRequestSOAP = new SoapObject(NAMESPACE, METHOD_NAME);
pi1 = new PropertyInfo();
pi1.setName("crsCode");
pi1.setValue("HNH");//get the string that is to be sent to the web service
pi1.setType(String.class);
resultRequestSOAP.addProperty(pi1);
SoapSerializationEnvelope envp = new SoapSerializationEnvelope(
SoapEnvelope.VER11);
envp.dotNet = true;
envp.setOutputSoapObject(resultRequestSOAP);
AndroidHttpTransport androidHttpTransport = new AndroidHttpTransport(
URL);
try {
androidHttpTransport.call(SOAP_ACTION, envp);
if (envp.bodyIn instanceof SoapFault) {
SoapResult = ((SoapFault) envp.bodyIn).faultstring;
System.out.println("==SoapResulght==="+SoapResult);
} else {
SoapObject resultsRequestSOAP = (SoapObject) envp.bodyIn;
SoapResult = resultsRequestSOAP.getProperty(0).toString();
System.out.println("==SoapResult==="+SoapResult);
}
// SoapObject obj = (SoapObject)envp.getResponse();
//
// System.out.println("resultsString"+obj);
return SoapResult;
} catch (Exception e) {
System.out.println("---------------------------"+e.toString());
Log.d("ppp", e.toString());
Toast.makeText(MainActivity.this,
"Check Network connectivety" + e.toString(),
Toast.LENGTH_LONG).show();
Log.v("WS Error->", e.toString());
return e.toString();
}
};
protected void onPostExecute(Object result) {
dialog.dismiss();
Toast.makeText(MainActivity.this,
"Check Network connectivety" + result,
Toast.LENGTH_LONG).show();
};
}.execute();
}
public boolean haveNetworkConnection() {
boolean haveConnectedWifi = false;
boolean haveConnectedMobile = false;
ConnectivityManager cm = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);
NetworkInfo[] netInfo = cm.getAllNetworkInfo();
for (NetworkInfo ni : netInfo) {
if (ni.getTypeName().equalsIgnoreCase("WIFI"))
if (ni.isConnected())
haveConnectedWifi = true;
if (ni.getTypeName().equalsIgnoreCase("MOBILE"))
if (ni.isConnected())
haveConnectedMobile = true;
}
return haveConnectedWifi || haveConnectedMobile;
}
}
System.out.println("==SoapResult==="+SoapResult);
Response
anyType{RID=201309201377831; alertDetailPopulated=false; alertsId=0; alertsSummary=null; destExpArrival=08:01; destSchArrival=08:00; destinationStation=anyType{crsCode=BKJ; stationName=Beckenham Junction; }; expArrival=07:49; expDepart=07:49; otherAlertPresent=false; platformNo=3; routeDetailPopulated=false; routeDetails=null; rsID=null; schArrival=07:49; schDepart=07:49; serviceAlertPresent=false; toc=SE; tocName=Southeastern; trainID=2M18; trainLastReportedAt=null; }
Now I want to print RID and alertDetailPopulated values.
解决方案
@Override
protected SoapObject doInBackground(String... params) {
// TODO Auto-generated method stub
Intent i=getIntent();
String a=i.getStringExtra("code");
CallSoap cs=new CallSoap();
resp= cs.Call(a);
System.out.println("ssssssssssssssssssssssssssssssssss"+resp);
return resp;
}
protected void onPostExecute(Object result) {
if(result!= null)
{
String[] testValues = new String[result.getPropertyCount()];
for(int j= 0; j< result.getPropertyCount(); j++){
testValues[j] = result.getProperty(j).toString();
String name=(result.getProperty(0).toString());
Toast.makeText(MainActivity.this,
"Check Network connectivety" + name
Toast.LENGTH_LONG).show();
};
这篇关于如何解析来自服务器对象来的SOAP网络服务?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文