调用Web服务时出错

发布于 2024-11-02 04:56:20 字数 2247 浏览 3 评论 0原文

即使添加 kSOAP 2 库 jar 文件后,我也无法调用 Web 服务

源代码:

  package com.example.web;  

  import org.ksoap2.SoapEnvelope;  
  import org.ksoap2.serialization.PropertyInfo;  
  import org.ksoap2.serialization.SoapObject;
  import org.ksoap2.serialization.SoapSerializationEnvelope;  
  import org.ksoap2.transport.AndroidHttpTransport;  

  import android.app.Activity;  
  import android.os.Bundle;  
  import android.widget.TextView;  
  import android.widget.Toast;  

  public class MyWebCall extends Activity {      
TextView tv;  
String Name_Space="http://web.exampl.com/";  
String Method_Name="add";  
String Soap_Action="http://web.exampl.com/add";  
String URL="http://MyServerIPaddress:8081/WebService/services/MyWebService?wsdl";  
      /** Called when the activity is first created. */  
      @Override  
      public void onCreate(Bundle savedInstanceState) {  
    super.onCreate(savedInstanceState);  
    setContentView(R.layout.main);  
    tv=(TextView)findViewById(R.id.txt);  
    SoapObject request=new SoapObject(Name_Space,Method_Name);  
    PropertyInfo pi1=new PropertyInfo();  
    pi1.setName("op1");  
    pi1.setValue(6);  
    pi1.setType(int.class);  
    request.addProperty(pi1);  
    PropertyInfo pi2=new PropertyInfo();  
    pi2.setName("op1");  
    pi2.setValue(9);  
    pi2.setType(int.class);  
    request.addProperty(pi2);  
    SoapSerializationEnvelope envelope=new SoapSerializationEnvelope(SoapEnvelope.VER11);  
    envelope.setOutputSoapObject(request);  
    AndroidHttpTransport androidHttpTransport=new AndroidHttpTransport(URL);  
    try{  
        androidHttpTransport.call(Soap_Action,envelope);  
        SoapObject response=(SoapObject) envelope.getResponse();  
        int result=Integer.parseInt(response.getProperty(0).toString());  
        System.out.println("Result ::::::::::::::: "+result);  
        tv.setText(response.getProperty(0).toString());  
        Toast.makeText(getApplicationContext(), response.getProperty(0).toString(),Toast.LENGTH_SHORT).show();  
    }catch(Exception e){  
        e.printStackTrace();  
        }  
   }  
  }  

我觉得jar中缺少一些类。我可以从哪里下载正确的 jar 文件?请帮助我。

谢谢&问候,
斯内哈

I am not able to call aweb service even after adding kSOAP 2 library jar file.

Source code :

  package com.example.web;  

  import org.ksoap2.SoapEnvelope;  
  import org.ksoap2.serialization.PropertyInfo;  
  import org.ksoap2.serialization.SoapObject;
  import org.ksoap2.serialization.SoapSerializationEnvelope;  
  import org.ksoap2.transport.AndroidHttpTransport;  

  import android.app.Activity;  
  import android.os.Bundle;  
  import android.widget.TextView;  
  import android.widget.Toast;  

  public class MyWebCall extends Activity {      
TextView tv;  
String Name_Space="http://web.exampl.com/";  
String Method_Name="add";  
String Soap_Action="http://web.exampl.com/add";  
String URL="http://MyServerIPaddress:8081/WebService/services/MyWebService?wsdl";  
      /** Called when the activity is first created. */  
      @Override  
      public void onCreate(Bundle savedInstanceState) {  
    super.onCreate(savedInstanceState);  
    setContentView(R.layout.main);  
    tv=(TextView)findViewById(R.id.txt);  
    SoapObject request=new SoapObject(Name_Space,Method_Name);  
    PropertyInfo pi1=new PropertyInfo();  
    pi1.setName("op1");  
    pi1.setValue(6);  
    pi1.setType(int.class);  
    request.addProperty(pi1);  
    PropertyInfo pi2=new PropertyInfo();  
    pi2.setName("op1");  
    pi2.setValue(9);  
    pi2.setType(int.class);  
    request.addProperty(pi2);  
    SoapSerializationEnvelope envelope=new SoapSerializationEnvelope(SoapEnvelope.VER11);  
    envelope.setOutputSoapObject(request);  
    AndroidHttpTransport androidHttpTransport=new AndroidHttpTransport(URL);  
    try{  
        androidHttpTransport.call(Soap_Action,envelope);  
        SoapObject response=(SoapObject) envelope.getResponse();  
        int result=Integer.parseInt(response.getProperty(0).toString());  
        System.out.println("Result ::::::::::::::: "+result);  
        tv.setText(response.getProperty(0).toString());  
        Toast.makeText(getApplicationContext(), response.getProperty(0).toString(),Toast.LENGTH_SHORT).show();  
    }catch(Exception e){  
        e.printStackTrace();  
        }  
   }  
  }  

I feel few classes are missing in jar. From where can i dwnld proper jar file? Pls help me.

Thanks & Regards,
Sneha

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

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

发布评论

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

评论(2

伴随着你 2024-11-09 04:56:20
AndroidHttpTransport androidHttpTransport=new AndroidHttpTransport(URL); 

我已将此行更改为:

HttpTransportSE androidHttpTransport = new HttpTransportSE(URL); 

并且效果很好。
还要感谢您提供完整的 rekaszeru 包。

AndroidHttpTransport androidHttpTransport=new AndroidHttpTransport(URL); 

I have changed this line to:

HttpTransportSE androidHttpTransport = new HttpTransportSE(URL); 

And it worked fine.
Also thanks for the full package rekaszeru.

无尽的现实 2024-11-09 04:56:20

KSoap2 要在 Android 上运行,核心库是不够的。

您需要 完整包

For KSoap2 to work on Android, the core library is not enough.

You need the full package.

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