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

发布于 2024-10-05 00:39:41 字数 2595 浏览 3 评论 0原文

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

    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 标签之前中断。我在虚拟屏幕上得到的只是:错误。 任何解决方案..我不知道问题出在哪里?

以下是 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>

This is my only class where i get connected to my web service :

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

    } }

I think it breaks before the TRY tag.. all i get on the virtual screen is : false.
Any solutions.. i don't know where is the problem ?

The following is a sample SOAP request and response.

<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>

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

苦笑流年记忆 2024-10-12 00:39:42

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

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

就是这样:)

I had the same problem I just add this permission in AndroidManifest.xml

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

Thats it :)

断桥再见 2024-10-12 00:39:42

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

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

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

make sure that in your android application config file you have allowed remote access.

Also try pasting the URL into a browser and see whether it is correct.

Also set a breakpoint or log in a file to determine whether the service will get invoked.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文