在调用Web服务的错误 [英] error in calling Web Service

查看:130
本文介绍了在调用Web服务的错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我不能够调用 Web服务即使加入 KSOAP 2库jar 文件。

来源$ C ​​$ C:

 包com.example.web;

  进口org.ksoap2.SoapEnvelope;
  进口org.ksoap2.serialization.PropertyInfo;
  进口org.ksoap2.serialization.SoapObject;
  进口org.ksoap2.serialization.SoapSerializationEnvelope;
  进口org.ksoap2.transport.AndroidHttpTransport;

  进口android.app.Activity;
  进口android.os.Bundle;
  进口android.widget.TextView;
  进口android.widget.Toast;

  公共类MyWebCall延伸活动{
TextView的电视;
字符串Name_Space =htt​​p://web.exampl.com/;
字符串METHOD_NAME =添加;
字符串Soap_Action =htt​​p://web.exampl.com/add;
字符串的URL =HTTP:// MyServerIPaddress:8081 / web服务/服务/为MyWebService WSDL;
      / **第一次创建活动时调用。 * /
      @覆盖
      公共无效的onCreate(包savedInstanceState){
    super.onCreate(savedInstanceState);
    的setContentView(R.layout.main);
    电视=(TextView中)findViewById(R.id.txt);
    SoapObject请求=新SoapObject(Name_Space,METHOD_NAME);
    的PropertyInfo PI1 =新的PropertyInfo();
    pi1.setName(OP1);
    pi1.setValue(6);
    pi1.setType(int.class);
    request.addProperty(PI1);
    的PropertyInfo PI2 =新的PropertyInfo();
    pi2.setName(OP1);
    pi2.setValue(9);
    pi2.setType(int.class);
    request.addProperty(PI2);
    SoapSerializationEnvelope包=新SoapSerializationEnvelope(SoapEnvelope.VER11);
    envelope.setOutputSoapObject(要求);
    AndroidHttpTransport androidHttpTransport =新AndroidHttpTransport(URL);
    尝试{
        androidHttpTransport.call(Soap_Action,包);
        SoapObject响应=(SoapObject)envelope.getResponse();
        INT结果=的Integer.parseInt(response.getProperty(0)的ToString());
        的System.out.println(结果:::::::::::::::+结果);
        tv.setText(response.getProperty(0)的ToString());
        Toast.makeText(getApplicationContext(),response.getProperty(0)的ToString(),Toast.LENGTH_SHORT).show();
    }赶上(例外五){
        e.printStackTrace();
        }
   }
  }
 

我觉得几个类中缺少罐子。从我在哪里可以DWNLD正确的jar文件?请帮助我。

感谢和放大器;问候,
Sneha

解决方案

  AndroidHttpTransport androidHttpTransport =新AndroidHttpTransport(URL);
 

我已经改变了这一行:

  HttpTransportSE androidHttpTransport =新HttpTransportSE(URL);
 

和它工作得很好。
 也感谢全包rekaszeru。

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

解决方案

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.

这篇关于在调用Web服务的错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆