-1

我已经使用 Ksoap 库在 android 中编写了简单的 Web 服务(实际上是按照教程进行的)。但似乎效果不佳。下面是我的简单代码:

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();
    }

}
}

我的文本视图中只收到响应“错误”。谁能告诉我这里有什么问题?

4

1 回答 1

0

我发现出了什么问题。我写:

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

代替

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

它现在正在工作。

于 2013-07-11T16:48:02.593 回答