从Android连接到我的Web服务(SOAP 1.1)时尝试获得任何响应

时间:2010-11-30 13:37:11

标签: android ksoap2 android-ksoap2

这是我唯一可以连接到我的网络服务的课程:

    public class Main extends Activity {
    /** Called when the activity is first created. */

 private static final String SOAP_ACTION="http://tempuri.org/getme/TSM/LogOn";
 private static final String METHOD_NAME="LogOn";
 private static final String NAMESPACE="http://tempuri.org/getme/TSM/";
 private static final String URL="http://theking/eget/WebService/WSAuth.asmx";

 @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);

        TextView tv = (TextView) findViewById(R.id.TextView01);

        SoapObject Request = new SoapObject(NAMESPACE, METHOD_NAME);
        Request.addProperty("strUsername", "Test");
        Request.addProperty("strPassword", "Test123");
        Request.addProperty("strMessage", "hello");

        SoapSerializationEnvelope soapEnvelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
        soapEnvelope.dotNet = true;
        soapEnvelope.setOutputSoapObject(Request);

        AndroidHttpTransport aht = new AndroidHttpTransport(URL);
        try
        {
         aht.call(SOAP_ACTION, soapEnvelope);
         SoapObject response = (SoapObject)soapEnvelope.getResponse();
            String LogonResult =  response.getProperty(0).toString();
            String MessageResult =  response.getProperty(1).toString();
         tv.setText("Status : " + LogonResult + " Message: " + MessageResult);
        }
        catch(Exception e)
        {
         e.printStackTrace();
        }

    } }

我认为它在TRY标签之前中断了...我在虚拟屏幕上看到的是:false。 任何解决方案..我不知道问题出在哪里?

以下是SOAP请求和响应的示例。

<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
  <soap:Body>
    <LogOn xmlns="http://tempuri.org/getme/TSM">
      <strUsername>string</strUsername>
      <strPassword>string</strPassword>
      <strMessage>string</strMessage>
    </LogOn>
  </soap:Body>
</soap:Envelope>

    <soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
  <soap:Body>
    <LogOnResponse xmlns="http://tempuri.org/getme/TSM">
      <LogOnResult>int</LogOnResult>
      <strMessage>string</strMessage>
    </LogOnResponse>
  </soap:Body>
</soap:Envelope>

2 个答案:

答案 0 :(得分:1)

我遇到了同样的问题,我只是在AndroidManifest.xml中添加了这个权限

<uses-permission android:name="android.permission.INTERNET" />

多数民众赞成:)

答案 1 :(得分:0)

确保在您的Android应用程序配置文件中允许远程访问。

还尝试将URL粘贴到浏览器中,看看它是否正确。

还设置断点或登录文件以确定是否将调用该服务。