2013-07-11 31 views
-1

我已經使用Ksoap庫編程(在Android中使用了簡單的Web服務)。但它似乎並不好。以下是我的簡單代碼:Web服務(.net),按預期工作

public class MainActivity extends Activity { 

TextView tv; 
SoapPrimitive response; 

final String SOAP_ACTION = "http://tempuri.org/CelsiusToFahrenheit"; 
final String METHOD_NAME = "CelsiusToFahrenheit"; 
final String NAMESPACE = "http://www.tempuri.org/"; 
final String URL = "http://www.w3schools.com/webservices/tempconvert.asmx"; 
@Override 
protected void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.activity_main); 

    tv = (TextView) findViewById(R.id.tv); 
    final Button button = (Button) findViewById(R.id.button1); 
    button.setOnClickListener(new View.OnClickListener() { 

     @Override 
     public void onClick(View v) { 
      getValue(); 

     } 
    }); 

} 

private void getValue() { 

    SoapObject soapObject = new SoapObject(NAMESPACE, METHOD_NAME); 
    soapObject.addProperty("Celsius", "33"); 


    SoapSerializationEnvelope serial = new SoapSerializationEnvelope(SoapEnvelope.VER11); 
    serial.dotNet = true; 
    serial.setOutputSoapObject(soapObject); 

    HttpTransportSE transport = new HttpTransportSE(URL); 

    try { 
     transport.call(SOAP_ACTION, serial); 
     response = (SoapPrimitive) serial.getResponse(); 
     tv.setText(response+""); 
    } catch (IOException e) { 
     e.printStackTrace(); 
    } catch (XmlPullParserException e) { 
     e.printStackTrace(); 
    } 

} 
} 

我只在我的文本視圖中得到響應「錯誤」。有誰能告訴我這裏有什麼問題嗎?

+0

爲什麼反對投票?請解釋.. – rootpanthera

回答

0

我發現有什麼問題。我寫道:的

final String NAMESPACE = "http://www.tempuri.org/"; 

代替

final String NAMESPACE = "http://tempuri.org/"; 

它的工作現在。