Web服务(.net),未按预期工作

时间:2013-07-11 16:23:02

标签: java android .net web-services

我使用Ksoap libary编写了(实际上是在教程中)简单的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();
    }

}
}

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

1 个答案:

答案 0 :(得分:0)

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

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

而不是

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

现在正在运作。