【问题标题】:KSOAP2 not returning any resultsKSOAP2 不返回任何结果
【发布时间】:2014-01-17 08:46:51
【问题描述】:

我正在使用 KSOAP2 库来调用 ASP.NET Web 服务。我没有收到任何错误,但我也没有收到任何解决此问题的任何想法。

下面是我的代码。我只是调用返回字符串的 helloworld 默认方法。

    public class MainActivity extends Activity {

        private final String NAMESPACE = "http://tempuri.org/";
        private final String URL = "http://(ip)/TrialService.asmx";
        private final String SOAP_ACTION = "http://tempuri.org/HelloWorld";
        private final String METHOD_NAME = "HelloWorld";
        TextView t1;

        @Override
        public void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.activity_main);
            t1 = (TextView) findViewById(R.id.textView1);

            SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME);
            if (android.os.Build.VERSION.SDK_INT > 9) {
                StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder()
                        .permitAll().build();
                StrictMode.setThreadPolicy(policy);
            }
            SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(
                    SoapEnvelope.VER11);
            envelope.dotNet = true;
            envelope.setOutputSoapObject(request);
            HttpTransportSE androidHttpTransport = new HttpTransportSE(URL);
            try {
                androidHttpTransport.call(SOAP_ACTION, envelope);
                String receivedInt = (String) envelope.getResponse();
                t1.setText(receivedInt);
                setContentView(t1);
            } catch (Exception e) {
                t1.setText("error");
            }
        }
    }       

【问题讨论】:

    标签: android asp.net web-services ksoap2 android-ksoap2


    【解决方案1】:

    首先从启用调试开始,这样您就可以看到您发送到服务器的soap信封的内容,您可以通过添加来做到这一点(参见注释部分):

    HttpTransportSE androidHttpTransport = new HttpTransportSE(URL);
    androidHttpTransport.debug = true;//ADD THIS
    try {
         androidHttpTransport.call(SOAP_ACTION, envelope);
         //ADD THESE 2
         //Important Outputs to check how the request/Response looks like.. Check them in Logcat to find these outputs
         System.out.println("requestDump is :"+androidHttpTransport.requestDump);//ADDED
         System.out.println("responseDump is :"+androidHttpTransport.responseDump);//ADDED
    
         String receivedInt = (String) envelope.getResponse();
         t1.setText(receivedInt);
         setContentView(t1);
    } catch (Exception e) {
            t1.setText("error");
    }
    

    现在您可以看到正在发送到服务器的肥皂信封,检查它是否准确。 (您可以将其与使用SoapUI. 之类的程序从桌面发送的信封进行比较)

    下一步:

    • 您必须提供更多详细信息,以便我们更好地帮助您:放一份您的相关 WSDL 部分的副本。

    • 确保您使用正确的值:NAMESPACE、METHOD_NAME、URL、SOAP_ACTION

    • 如果这是一个测试项目并且您可以访问服务器,您可以将其作为奖励来检查当您发送请求。

    更多参考资料可以帮助您查看我的答案:link1、link2、link3、link4

    【讨论】:

      猜你喜欢
      • 2017-12-28
      • 2017-12-09
      • 2020-10-03
      • 2017-03-19
      • 2017-05-20
      • 2012-08-08
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多