Android设备无法正常工作

时间:2012-07-28 04:10:11

标签: android soap android-emulator device

我已经使用soap webservices开发了一个计算示例。我在我的模拟器上工作得很好。但它在我的android实际设备上没有工作。为什么dis不能在我的设备上工作。

dis是我的代码:

package org.web.frontend.calculator;
import java.io.IOException;
import java.net.SocketException;

import org.ksoap2.SoapEnvelope;
import org.ksoap2.serialization.SoapObject;
import org.ksoap2.serialization.SoapSerializationEnvelope;
import org.ksoap2.transport.HttpTransportSE;
import org.ksoap2.transport.ServiceConnection;
import org.xmlpull.v1.XmlPullParserException;

import android.app.Activity;
import android.os.Bundle;
import android.widget.TextView;
import android.util.Log;
public class AndroidWSDLFrontEnd extends Activity {

private String METHOD_NAME ="sum";
private String NAMESPACE = "http://calculator.backend.web.org";
private String SOAP_ACTION = NAMESPACE + METHOD_NAME; // NAMESPACE + method name
private static final String URL = "http://192.168.1.168:8085/Calculation/services /Calculate?wsdl"; // you must use ipaddress here, don’t use Hostname or localhost

/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
TextView tv = (TextView) findViewById(R.id.txtAddition);


try
{
SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME);
request.addProperty("i", 15);
request.addProperty("j", 10);

SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
envelope.dotNet = true;
envelope.setOutputSoapObject(request);
HttpTransportSE androidHttpTransport = new HttpTransportSE(URL);
androidHttpTransport.call(SOAP_ACTION,envelope);
Object result = envelope.getResponse();
System.out.println("Result : " + result.toString());
((TextView) findViewById (R.id.txtAddition)).setText("Addition : "+result.toString());
} catch (SocketException E) {
 E.printStackTrace();
((TextView) findViewById (R.id.txtAddition)).setText("ERROR: "   +    E.getClass().getName() + ":" + E.getMessage());
  }
 catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
    } catch (XmlPullParserException e) {
// TODO Auto-generated catch block
e.printStackTrace();
  }
   }
    }

请帮帮我。

2 个答案:

答案 0 :(得分:0)

听起来你和http://192.168.1.168:8085/Calculation/services/Calculate?wsdl%22不在同一个网络上。你在移动网络上吗?如果是这样,请连接到Wi-Fi并尝试。此外,如果需要,您可能必须为您的网络配置代理或VPN以允许访问。

答案 1 :(得分:0)

检查您的移动IP地址,并将其替换为您当前给定的ipadrees

private static final String URL = "http://192.168.1.168:8085/Calculation/services /Calculate?wsdl";

请检查您使用的网络连接