【问题标题】:Web service (.net ), not working as expectedWeb 服务 (.net),未按预期工作
【发布时间】:2013-07-11 16:23:02
【问题描述】:

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

}
}

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

【问题讨论】:

  • 为什么要投反对票?请解释..

标签: java android .net web-services


【解决方案1】:

我发现了问题所在。我写道:

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

而不是

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

现在可以了。

【讨论】:

    猜你喜欢
    • 2019-06-02
    • 1970-01-01
    • 2019-10-28
    • 2017-10-21
    • 1970-01-01
    • 1970-01-01
    • 2014-05-15
    • 1970-01-01
    • 2022-08-17
    相关资源
    最近更新 更多