幸运星空

Lucker的程序人生

  博客园 :: 首页 :: 博问 :: 闪存 :: 新随笔 :: 联系 :: 订阅 订阅 :: 管理 ::

1,在AdroidManifest.xml中加入权限

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

2,导入ksoap2包

3,private String NameSpace="命名空间";

   private String Url="---.asmx";//WebService发布地址

   private String MethodName="方法名";

   private String SoapAction="命名空间/方法名";

   private SoapObject request=null;
    private SoapPrimitive result=null;//要注意result类型
    private SoapSerializationEnvelope envelope=null;
    private HttpTransportSE androidHttpTransport=null;

 

4,androidHttpTransport=new HttpTransportSE(Url);
     androidHttpTransport.debug=true;
     request=new SoapObject(NameSpace,MethodName);
  request.addProperty("para1","zy");
  request.addProperty("para2","123");
  envelope=new SoapSerializationEnvelope(SoapEnvelope.VER11);
  envelope.dotNet=true;//表示不用rpc方式
  envelope.setOutputSoapObject(request);
  envelope.bodyOut=request;
     try{   
      androidHttpTransport.call(SoapAction, envelope);
      result=(SoapPrimitive)envelope.getResponse();
      String sb;
      sb=result.toString();
      Toast.makeText(this, "result is"+sb, Toast.LENGTH_SHORT).show();
     }
     catch(Exception e)
     {
      Log.e(TAG,"WebService Failed",e);
      return;
     }

posted on 2011-08-09 10:24  Lucker  阅读(504)  评论(1编辑  收藏  举报