Android:关于ksoap2和webservice

时间:2011-09-15 05:12:45

标签: android web-services wsdl ksoap2

我得到了wsdl和URL,服务器是用C ++编写的; 我在android中使用KSoap2来访问该方法,但它总是如此 打印出来:“方法'方法名'未实现'!!! 谁能帮我吗? 提前谢谢!

4 个答案:

答案 0 :(得分:1)

您是否正确创建了您的请求和SoapAction

尝试下面的示例(它是一个带有0个参数的公共Web服务),看看它是否适合您。

private static final String WSDL_URL = "http://wsf.cdyne.com/WeatherWS/Weather.asmx?WSDL";
private static final String WS_NAMESPACE = "http://ws.cdyne.com/WeatherWS/";
private static final String WS_METHOD_NAME = "GetWeatherInformation";

// 1. Creating SOAP request with no arguments
SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
envelope.setOutputSoapObject(new SoapObject(WS_NAMESPACE, WS_METHOD_NAME));

// 2. Create a HTTP Transport object to send the web service request
HttpTransportSE httpTransport = new HttpTransportSE(WSDL_URL);
httpTransport.debug = true; // allows capture of raw request/respose in Logcat

// 3. Make the web service invocation
httpTransport.call(WS_NAMESPACE + WS_METHOD_NAME, envelope);

Log.d(TAG, "HTTP REQUEST:\n" + httpTransport.requestDump);
Log.d(TAG, "HTTP RESPONSE:\n" + httpTransport.responseDump);

查看详细的教程,解释using kSOAP2 with Android

的基础知识

答案 1 :(得分:0)

在这里看到ksoap的简单示例可以帮助http://vimeo.com/9633556

答案 2 :(得分:0)

private static final String NAMESPACE = "http://tempuri.org/";
private static final String URL = "http://216.128.29.26/webservices/TempConvert.asmx";
private static final String SOAP_ACTION = "http://tempuri.org/CelsiusToFahrenheit";
private static final String METHOD_NAME = "CelsiusToFahrenheit"

您应该如上所述指定必要的字段。

答案 3 :(得分:0)

private static final String NAMESPACE = "http://tempuri.org/";
private static final String URL = "http://216.128.29.26/webservices/TempConvert.asmx";
private static final String SOAP_ACTION = "http://tempuri.org/CelsiusToFahrenheit";
private static final String METHOD_NAME = "CelsiusToFahrenheit";

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);
    TextView tv;
    tv = (TextView) findViewById(R.id.tv);
    tv.setText(ws());
}
public String ws() {
    String result = "";
    try
    {
        SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME);
        request.addProperty("Celsius", "32");

        SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(
                SoapEnvelope.VER11);

        envelope.dotNet = true;

        envelope.setOutputSoapObject(request);

        HttpTransportSE ht = new HttpTransportSE(URL);
        ht.call(SOAP_ACTION, envelope);

        if(envelope.getResponse()!=null){
            SoapPrimitive response = (SoapPrimitive) envelope.getResponse();
            result = "FeranHit : " + response.toString();
        }   
    }
    catch (Exception e) 
    {
        result = e.getMessage();
    }
    return result;
}

看到这是我的代码。并获得完整的结果。这只是ksoap2的测试程序。

  

我这里没有包含任何库。