您好,使用網絡服務。 我正在做一個POC。 這是我的活動課: 我使用ksoap2。如何在android中解析和顯示WCF的內容?
package ab.tina;
import java.io.InputStream;
import java.net.URI;
import org.ksoap2.SoapEnvelope;
import org.ksoap2.serialization.SoapObject;
import org.ksoap2.serialization.SoapPrimitive;
import org.ksoap2.serialization.SoapSerializationEnvelope;
import org.ksoap2.transport.HttpTransportSE;
import android.app.Activity;
import android.os.Bundle;
import android.util.Log;
import android.widget.TextView;
public class TinaWebActivity extends Activity {
private TextView txtview;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
txtview=(TextView)findViewById(R.id.textView1);
try {
SoapObject Request = new SoapObject("http://www.webserviceX.NET/", "GetQuote");
Request.addProperty("symbol", "MFST");
SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
envelope.dotNet = true;
envelope.setOutputSoapObject(Request);
HttpTransportSE androidHttpTransport = new HttpTransportSE("http://www.webservicex.net/stockquote.asmx");
Log.e("tag1","err1");
androidHttpTransport.call("http://www.webserviceX.NET/GetQuote", envelope);
Log.e("tag2","err2");
SoapPrimitive response = (SoapPrimitive)envelope.getResponse();
Log.e("tag3","err3");
//String str=(String)response.getProperty(1);
txtview.setText(response.toString());
//txtview.setText(response.toString());
Log.e("tag4","err4");
}
catch (Exception e) {
Log.e("tag5","err5");
txtview.setText(e.getMessage());
}
}
}
我m如果結果是這樣的:
<string xmlns="http://www.webserviceX.NET/">
<StockQuotes><Stock><Symbol>MFST</Symbol><Last>0.00</Last><Date>N/A</Date><Time>N/A</Time><Change>N/A</Change><Open>N/A</Open><High>N/A</High><Low>N/A</Low><Volume>N/A</Volume><MktCap>N/A</MktCap><PreviousClose>N/A</PreviousClose><PercentageChange>N/A</PercentageChange><AnnRange>N/A - N/A</AnnRange><Earns>N/A</Earns><P-E>N/A</P-E><Name>MFST</Name></Stock></StockQuotes>
</string>
請告訴我如何可以解析它。我將需要哪些課程以及我應該使用哪種方法?
檢查這些了,可能有所幫助:http://www.kevingao.net/wcf-java-interop和http ://www.kevingao.net/wcf-java-interop/java-client-and-wcf-server.html或http://java.sun.com/developer/technicalArticles/glassfish/ProjectTango/ - http:// social.msdn.microsoft.com/forums/en-US/wcf/thread/4c5d88fb-5427-4024-aef1-94b601745dd1/ – bkdc