2014-01-17 51 views
0

我正在使用KSOAP2库调用ASP.NET Web服务。我没有得到任何错误,但我也没有得到任何答案任何想法来解决这个问题。KSOAP2不返回任何结果

以下是我的代码。我只是简单地调用返回字符串的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"); 
      } 
     } 
    }  

回答

0

首先通过启用调试,这样就可以看到你向服务器发送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部分。

  • 确保您使用的是正确的值:命名空间METHOD_NAME,网址,SOAP_ACTION

  • 如果这是一个测试项目,你可以访问服务器,你可以把它作为一个奖金检查发送请求时服务器上发生了什么。

更多的参考,可以帮助你看到我的答案在:link1link2link3link4