欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

Android通過ksoap2傳遞復(fù)雜數(shù)據(jù)類型及CXF發(fā)布的webservice詳細(xì)介紹

 更新時(shí)間:2017年02月24日 11:36:58   投稿:lqh  
這篇文章主要介紹了 Android通過ksoap2傳遞復(fù)雜數(shù)據(jù)類型詳細(xì)介紹的相關(guān)資料,需要的朋友可以參考下

 Android通過ksoap2傳遞復(fù)雜數(shù)據(jù)類型及CXF發(fā)布的webservice詳細(xì)介紹

最近在學(xué)校搞點(diǎn)東西,搞了2天的webservice,心累呀,今天中午和小伙伴終于弄通了,感覺就是一些細(xì)節(jié)問題沒有注意到,啊,我的時(shí)間呀,進(jìn)這么過去了,為了不讓小伙伴們走彎路,我還是認(rèn)真的把開發(fā)文檔寫一遍吧!

首先,如果我們要用CXF發(fā)布webservice用自定義類型的對(duì)象來當(dāng)參數(shù)傳遞的話,我們應(yīng)該先把這個(gè)類序列化一遍,下面就是我測(cè)試的代碼,我創(chuàng)建了一個(gè)TGrade類,實(shí)現(xiàn)了KvmSerializable接口,這個(gè)接口里面的三個(gè)方法,這個(gè)接口的好處在于不需要服務(wù)端在去反序列化實(shí)體對(duì)象了,

public class TGrade implements KvmSerializable { 
 
  // Fields 
 
  private Integer GId; 
  private Integer GMax; 
  private Integer GMin; 
  private String GName; 
  private String GPic; 
  private String GType; 
   
  // Constructors 
  /** default constructor */ 
  public TGrade() { 
  } 
 
  /** minimal constructor */ 
  public TGrade(Integer GMax) { 
    this.GMax = GMax; 
  } 
 
  /** full constructor */ 
  public TGrade(Integer GMax, Integer GMin, String GName, String GPic, 
      String GType) { 
    this.GMax = GMax; 
    this.GMin = GMin; 
    this.GName = GName; 
    this.GPic = GPic; 
    this.GType = GType; 
  } 
 
  // Property accessors 
  public Integer getGId() { 
    return this.GId; 
  } 
 
  public void setGId(Integer GId) { 
    this.GId = GId; 
  } 
 
  public Integer getGMax() { 
    return this.GMax; 
  } 
 
  public void setGMax(Integer GMax) { 
    this.GMax = GMax; 
  } 
 
  public Integer getGMin() { 
    return this.GMin; 
  } 
 
  public void setGMin(Integer GMin) { 
    this.GMin = GMin; 
  } 
 
  public String getGName() { 
    return this.GName; 
  } 
 
  public void setGName(String GName) { 
    this.GName = GName; 
  } 
 
  public String getGPic() { 
    return this.GPic; 
  } 
 
  public void setGPic(String GPic) { 
    this.GPic = GPic; 
  } 
 
  public String getGType() { 
    return this.GType; 
  } 
 
  public void setGType(String GType) { 
    this.GType = GType; 
  } 
 
  @Override 
  public Object getProperty(int arg0) { 
    switch (arg0) {  
    case 0:  
      return GId;  
    case 1:  
      return GMax;  
    case 2:  
      return GMin;  
    case 3:  
      return GName;  
    case 4:  
      return GPic; 
    case 5:  
      return GType;  
    default:  
      break;  
    }  
    return null;  
  } 
 
  @Override 
  public int getPropertyCount() { 
    // TODO Auto-generated method stub 
    return 6;//y要注意這里,必須等于參數(shù)的個(gè)數(shù),不然服務(wù)端沒有辦法接受有些參數(shù) 
  } 
 
  @Override 
  public void getPropertyInfo(int arg0, Hashtable arg1, PropertyInfo arg2) { 
    switch (arg0) { 
    case 0:  
      arg2.type = PropertyInfo.STRING_CLASS;  
      arg2.name = "GId";  
      break;  
    case 1:  
      arg2.type = PropertyInfo.STRING_CLASS;  
      arg2.name = "GMax";  
      break;  
    case 2:  
      arg2.type = PropertyInfo.STRING_CLASS;  
      arg2.name = "GMin";  
      break;  
    case 3:  
      arg2.type = PropertyInfo.STRING_CLASS;  
      arg2.name = "GName";  
      break;  
    case 4:  
      arg2.type = PropertyInfo.STRING_CLASS;  
      arg2.name = "GPic";  
      break;  
    case 5:  
      arg2.type = PropertyInfo.STRING_CLASS;  
      arg2.name = "GType";  
      break;  
    default:  
      break;  
    }     
  } 
 
  @Override 
  public void setProperty(int arg0, Object arg1) { 
    switch (arg0) { 
    case 0: 
      GId=Integer.parseInt(arg1.toString()); 
      break; 
    case 1: 
      GMax=Integer.parseInt(arg1.toString()); 
 
      break; 
    case 2: 
      GMin=Integer.parseInt(arg1.toString()); 
 
      break; 
    case 3: 
      GName=arg1.toString(); 
 
      break; 
    case 4: 
      GPic=arg1.toString(); 
 
      break; 
    case 5: 
 
      GType=arg1.toString(); 
      break; 
 
    default: 
      break; 
    } 
  } 
 
 
 
} 
 
//-----------------------------下面是我測(cè)試部分的代碼,這部分代碼很重要,需要認(rèn)真的看,我也寫的比較詳細(xì),代碼的世界模糊不得 
 
public boolean addMaintenanceInfo() { 
    String methodName = "addGrade";//服務(wù)端的方法 
    String soapAction =“http://10.127.80.67/gbckf/Android/GradeService”+methodName; 
     
    TGrade person = new TGrade(); 
    person.setProperty(0, "6"); 
    person.setProperty(1, 1); 
    person.setProperty(3, "1"); 
    person.setProperty(4, "1"); 
    person.setProperty(5, "1"); 
    // 建立webservice連接對(duì)象 
    HttpTransportSE transport = new HttpTransportSE(AgbcApi.GRADESERVICEURL,5000);//5秒超時(shí) 
    transport.debug = true;// 是否是調(diào)試模式 
    // 設(shè)置連接參數(shù) 
    SoapObject soapObject = new SoapObject(AgbcApi.NAMESPACE, methodName); 
    PropertyInfo objekt = new PropertyInfo(); 
    objekt.setName("arg0");//這個(gè)arg0很重要,不能是其他的東西,只能是arg0,不要問我為何,不然你就永遠(yuǎn)接受不了參數(shù),因?yàn)槭莤ml文檔類型的東西 
    objekt.setValue(person); 
    objekt.setType(TGrade.class); 
    soapObject.addProperty(objekt); 
    // 設(shè)置返回參數(shù) 
    SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);// soap協(xié)議版本必須用SoapEnvelope.VER11(Soap 
    envelope.dotNet = false;// 注意:這個(gè)屬性是對(duì)dotnetwebservice協(xié)議的支持,如果dotnet的webservice 
    envelope.bodyOut = transport; 
    Log.i("請(qǐng)求參數(shù)", soapObject.toString()); 
    envelope.setOutputSoapObject(soapObject);// 設(shè)置請(qǐng)求參數(shù) 
      envelope.addMapping(AgbcApi.NAMESPACE, "addGrade", TGrade.class);// 傳對(duì)象時(shí)必須,參數(shù)namespace是webservice中指定的, 
      (new MarshalBase64()).register(envelope); 
      try { 
      transport.call(soapAction, envelope); 
      if(envelope.bodyIn instanceof SoapFault){ 
        String str = ((SoapFault) envelope.bodyIn).faultstring; 
        Log.i("空節(jié)點(diǎn)返回的東西", str); 
      }else { 
        // SoapObject sb = (SoapObject)envelope.bodyIn;//服務(wù)器返回的對(duì)象存在envelope的bodyIn中 
        Object obj = envelope.getResponse();// 直接將返回值強(qiáng)制轉(zhuǎn)換為已知對(duì)象 
        //Log.d("WebService", "返回結(jié)果:" + obj.toString()); 
      } 
    } 
    catch (IOException e) { 
      e.printStackTrace(); 
    } 
    catch (XmlPullParserException e) { 
      e.printStackTrace(); 
    } 
    catch (Exception ex) { 
      ex.printStackTrace(); 
    } 
 
    return true; 

上面是我親手寫的代碼,若是沒有明白小伙伴,給我留言我給你看看吧,注意請(qǐng)求網(wǎng)絡(luò)不能放在主線程哦,不然要報(bào)錯(cuò)的

感謝閱讀,希望能幫助到大家,謝謝大家對(duì)本站的支持!

相關(guān)文章

最新評(píng)論