2012-07-20 39 views
-1

現在我消耗在Android SOAP Web服務/ eclipse.Well其工作fine.Please查找我的服務鏈接無法在Android /消費Web服務的價值蝕

http://54.251.60.177/MobileWS/Student.asmx?wsdl

「GetStudentInformation 「,這是我正在制定的服務和它的輸入值是」111105009「

如果我把這個值作爲上述服務的輸入,它只顯示仿真器上的下面的圖像的結果,並且還顯示這些東西公開。

IMAGE_1

enter image description here

IMAGE_2 enter image description here

但在這裏我的問題是,上述IMAGE_2正顯示出所有的答案中的XML標記,但我只需要表現出答案就像我在image_2上提到的那樣。如何實現這個概念?

請在下面找到

WebMethod.java

public class GetStudentInformation 
{ 
public String GetStudentInformation(String sStudentCode) 
{ 
    return sStudentCode; 
} } 

Demo_tabActivity.java我的消息來源

public class Demo_tabActivity extends Activity 
{ 
private static String NAMESPACE = "http://tempuri.org/"; 
private static String METHOD_NAME = "GetStudentInformation"; 
private static String SOAP_ACTION = "http://tempuri.org/GetStudentInformation"; 
private static String URL = "http://54.251.60.177/MobileWS/Student.asmx?WSDL"; 

Button btnFar; 
EditText txtFar; 

    @Override 
    public void onCreate(Bundle savedInstanceState) 
    { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.main); 

     txtFar = (EditText)findViewById(R.id.editText_in); 
     btnFar = (Button)findViewById(R.id.button1); 
     btnFar.setOnClickListener(new View.OnClickListener() 
     { 
     public void onClick(View v) 
     { 
     String b; 

     //Initialize soap request + add parameters 
     SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME); 

     //Use this to add parameters 

     request.addProperty("sStudentCode",txtFar.getText().toString()); 

     //Declare the version of the SOAP request 

     SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11); 

     envelope.setOutputSoapObject(request); 

     envelope.dotNet = true; 

     try 
     { 
      HttpTransportSE androidHttpTransport = new HttpTransportSE(URL); 

      //this is the actual part that will call the webservice 

      androidHttpTransport.call(SOAP_ACTION, envelope); 

      // Get the SoapResult from the envelope body. 

      SoapPrimitive result = (SoapPrimitive)envelope.getResponse(); 


      if (result != null) 
      { 
       //Get the first property and change the label text 

       b = result.toString(); 
       Intent myIntent = new Intent(Demo_tabActivity.this, Tabhost.class); 

       myIntent.putExtra("result1", b); 
       startActivity(myIntent); 
      } 
      else 
      { 
       Toast.makeText(getApplicationContext(), "No Response",Toast.LENGTH_SHORT).show(); 
      } 
     } 
     catch (Exception e) 
     { 
      e.printStackTrace(); 
      } 
     } 
     }); 
    } 
} 

Tabhost.java

public class Tabhost extends TabActivity { 

@Override 
public void onCreate(Bundle savedInstanceState) { 

    super.onCreate(savedInstanceState); 
    setContentView(R.layout.main1); 

    String result1; 

    Bundle extras = getIntent().getExtras(); 

    if(extras!=null) 
    { 
     result1 = extras.getString("result1"); 
    } else result1 = "Didnt work !" ; 



    TabHost tabHost = getTabHost(); 
    TabHost.TabSpec spec; 
    Intent intent; 

    intent = new Intent().setClass(this, Tab_1.class); 
    intent.putExtra("result1", result1); 
    spec = tabHost.newTabSpec("first").setIndicator("First").setContent(intent); 
    tabHost.addTab(spec); 

    intent = new Intent().setClass(this, Tab_2.class); 
    spec = tabHost.newTabSpec("second").setIndicator("Second").setContent(intent); 
    tabHost.addTab(spec); 

    tabHost.setCurrentTab(0); 
} 
} 

Tab_1.java

public class Tab_1 extends Activity 
{ 
TextView tv1; 
String result1; 

/** Called when the activity is first created. */ 

@Override 
public void onCreate(Bundle savedInstanceState) 
{ 
super.onCreate(savedInstanceState); 
setContentView(R.layout.main2); 

Bundle extras = getIntent().getExtras(); 
if(extras != null) 
{ 
    result1 = extras.getString("result1"); 
} 
else result1 = "didnt work"; 

    tv1 = (TextView)findViewById(R.id.textView_main2); 
    tv1.setText(result1); 


} 
} 

Tab_2.java

public class Tab_2 extends Activity { 


/** Called when the activity is first created. */ 

@Override 
public void onCreate(Bundle savedInstanceState) { 

    super.onCreate(savedInstanceState); 
    setContentView(R.layout.main3); 
    } 
} 

感謝您的寶貴幫助!...

+0

http://www.jondev.net/articles/Android_XML_SAX_Parser_Example此鏈接中包含的Android XML SAX解析器的例子。它可能會幫助你。 – Venkatesh 2012-07-20 13:15:14

回答