2012-11-19 80 views
7

我是從我的KSOAP的WebMethod採取一個複雜的參數UpdatableCustomerInfo傳遞複雜參數從KSOAP的Android到WCF web服務

public class UpdatableCustomerInfo implements KvmSerializable { 

public String CustomerId; 
public String Facebook; 

@Override 
public Object getProperty(int arg0) { 
    String retVal = ""; 
    switch(arg0) 
     { 
     case 0: 
      retVal = CustomerId; 
      break; 

     case 1: 
      retVal = Facebook; 
      break; 
     } 

     return retVal; 
} 

@Override 
public int getPropertyCount() { 
    return 2; 
} 

@Override 
public void getPropertyInfo(int arg0, Hashtable arg1, PropertyInfo arg2) { 
    switch(arg0) 
     { 
     case 0: 
      arg2.type = PropertyInfo.STRING_CLASS; 
      arg2.name = "CustomerId"; 
      break; 
     case 1: 
      arg2.type = PropertyInfo.STRING_CLASS; 
      arg2.name = "Facebook"; 
      break; 

     default:break; 
     } 
} 

@Override 
public void setProperty(int arg0, Object arg1) { 
    switch(arg0) 
    { 
    case 0: 
     CustomerId = arg1.toString(); 
     break; 
    case 1: 
     Facebook = arg1.toString(); 
     break; 

    default: 
     break; 
    } 
} 

}

調用.NET WCF Web服務,這是我的Web服務調用WebService

UpdatableCustomerInfo ucInfo = new UpdatableCustomerInfo(); 
    ucInfo.CustomerId = "1f089071-c126-e211-9b2e-dca971c098f5"; 
    ucInfo.Facebook = "asdfqwer1234"; 

    PropertyInfo pInfo = new PropertyInfo(); 
    pInfo.setName("updatableInfo"); 
    pInfo.setValue(ucInfo); 
    pInfo.setType(UpdatableCustomerInfo.class); 

    SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME); 
    request.addProperty(pInfo); 

    SoapSerializationEnvelope envelop = new SoapSerializationEnvelope(SoapEnvelope.VER11); 
    envelop.setOutputSoapObject(request); 
    envelop.dotNet = true; 

    HttpTransportSE hts = new HttpTransportSE(URL); 
    hts.debug = true; 

      try { 
     hts.call(SOAP_ACTION, envelop); 
    } catch (Exception ex) { 
     ex.printStackTrace(); 
    } 

但事實上,我記錄了Web服務方法和日誌告訴我,該方法被調用,但參數爲空。

我試過的SoapEnvelope版本改爲SoapEnvelope.VER10但就Web服務的方法的參數來爲NOT NULL,但沒有什麼,我在ucInfo

+0

我已添加賞金以獲得一些答案。尼克勞斯 - 如果你已經解決了這個問題,然後請回答並享受賞金:) –

+0

@USER_NAME - 哇!我還希望有人爲我的所有問題開放boutnties)) – MikroDel

+0

發佈示例SOAP請求 – Atrix1987

回答

2

爲什麼不使用此函數來調用SOAP Web服務?

// Register User By Facebook 
public static String RegisterUserByFacebook(String FBIDValue, String FBMailIDValue,String UserNameValue, String RegisterChipsValue) { 

    String responce = null; 

    SoapObject request = new SoapObject(SOAP_NAMESPACE, SOAP_METHOD_RegisterUserByFacebook); 

    PropertyInfo FBID = new PropertyInfo(); 
    PropertyInfo FBMailID = new PropertyInfo(); 
    PropertyInfo UserName = new PropertyInfo(); 
    PropertyInfo DeviceType = new PropertyInfo(); 
    PropertyInfo RegisterChips = new PropertyInfo(); 

    FBID.setName("fbid"); 
    FBID.setValue(FBIDValue); 

    FBMailID.setName("fbmailid"); 
    FBMailID.setValue(FBMailIDValue); 

    UserName.setName("name"); 
    UserName.setValue(UserNameValue); 

    DeviceType.setName("devicetype"); 
    DeviceType.setValue("android"); 

    RegisterChips.setName("Regchips"); 
    RegisterChips.setValue(RegisterChipsValue); 

    request.addProperty(FBID); 
    request.addProperty(FBMailID); 
    request.addProperty(UserName); 
    request.addProperty(DeviceType); 
    request.addProperty(RegisterChips); 

    SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11); 
    envelope.dotNet = true; 
    envelope.setOutputSoapObject(request); 
    HttpTransportSE aht = new HttpTransportSE(SOAP_URL); 
    try { 
     aht.call(SOAP_ACTION_RegisterUserByFacebook, envelope); 
     SoapPrimitive LoginResult; 
     LoginResult = (SoapPrimitive)envelope.getResponse(); 
     System.out.println("=================Register User Results: "+LoginResult.toString()); 
     //System.out.println(LoginResult.toString()); 
     responce = LoginResult.toString(); 
    } catch (IOException e) { 
     e.printStackTrace(); 
    } catch (XmlPullParserException e) { 
      e.printStackTrace(); 
    } 

    return responce; 
} 

只需將我的參數,屬性和URL替換爲您的參數,屬性和URL,您就會得到結果。

上述方法在我的情況下完美。

隨時發表評論。

+0

因爲OP想將複雜的參數傳遞給soap請求。這個答案將不起作用。我試過了。 –

6

好的。你想要'從ksoap2請求傳遞複雜參數'。

我已經面對你面對的確切問題。

我有AlertNative方法來解決這個問題,我已經描述如下。

首先,讓我知道我有搜索HEREHEREHEREHERE和許多SO鏈接。但沒有找到解決這個問題的辦法。

最後我來到鏈接How to send a soap request in android?作爲我第一步到這個解決方案。

Solution is

我有最後手動構建請求XML,並將其發送到 KSOAP用於發送和響應處理

Question is How?由以下方式

我面對的是什麼問題: 這裏是My SO Question,我把這裏作爲問題,但不能得到它的解決方案。

現在,當你看到裏面了SoapUI我的SOAP請求是:

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:test="http://test.login/"> 
    <soapenv:Header/> 
    <soapenv:Body> 
     <test:Login> 
     <!--Optional:--> 
     <arg0>best_buyer_editor</arg0> 
     <!--Optional:--> 
     <arg1>welcome</arg1> 
     <!--Optional:--> 
     <arg2>Mobile</arg2> 
     </test:Login> 
    </soapenv:Body> 
</soapenv:Envelope> 

內的soapUI我的SOAP響應是:

<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"> 
    <soap:Body> 
     <ns2:LoginResponse xmlns:ns2="http://test.login/"> 
     <return>{"LoginDetails":{"Result":"Success","UserName":"Best Buyer Editor","token":"M7M5RMQU6","rolelist":["buyer_editor","admin_role"],"parties":[{"partynumber":"BEST","type":"self","sites":[{"companyname":"www.bestmanufacture.com","sitecode":"BESTTXUSA-1","siteaddress":"225 E Industrial Blvd Waco USA"},{"companyname":"www.bestmanufacture.com","sitecode":"BESTNYUSA-5","siteaddress":"20 Milburn St Buffalo USA"},{"companyname":"Best Engineers Manufacturing USA Inc","sitecode":"BESTHQ","siteaddress":"8976, Hope vision Lane Simple City USA"},{"companyname":"www.bestmanufacture.com","sitecode":"BESTNYUSA-6","siteaddress":"Cedar &amp; Ellicott Sts Batavia USA"},{"companyname":"www.bestmanufacture.com","sitecode":"BESTTXUSA-2","siteaddress":"9700 Richmond Ave Ste 201 Houston USA"},{"companyname":"www.bestmanufacture.com","sitecode":"BESTTXUSA-4","siteaddress":"3315 Ashlock Dr Houston USA"},{"companyname":"Best Engineers Manufacturing USA Inc","sitecode":"BESTWH","siteaddress":"1021, Industrial Bolevar San Macros City USA"},{"companyname":"www.bestmanufacture.com","sitecode":"BESTNYMEX-10","siteaddress":"271 Madison Ave Ste 1003 New York USA"},{"companyname":"www.bestmanufacture.com","sitecode":"BESTNYUSA-8","siteaddress":"271 Madison Ave Ste 1003 New York USA"},{"companyname":"Best Engineers Manufacturing Europe Inc","sitecode":"BESTMO","siteaddress":"789,Future Vision Towers London GBR"},{"companyname":"www.bestmanufacture.com","sitecode":"BESTNYUSA-7","siteaddress":"1580 Columbia Tpke Ste 5 Castleton On Hudson USA"},{"companyname":"www.bestmanufacture.com","sitecode":"BESTNYMEX-9","siteaddress":"271 Madison Ave Ste 1003 New York USA"},{"companyname":"www.bestmanufacture.com","sitecode":"BESTTXUSA-3","siteaddress":"2821 Lackland Rd Ste 340 Fort Worth USA"}]},{"partynumber":"DHL","type":"sponsors","sites":[{"companyname":"www.dhl.com","sitecode":"DHLTXUSA-2","siteaddress":"11311 N Central Expy Dallas USA"},{"companyname":"www.dhl.com","sitecode":"DHLNYUSA-7","siteaddress":"150 W 22nd St Fl 5 New York USA"},{"companyname":"www.dhl.com","sitecode":"DHLNYMEX-9","siteaddress":"One Markin Lane Wyoming USA"},{"companyname":"www.dhl.com","sitecode":"DHLNYUSA-6","siteaddress":"12685 State Route 38 Berkshire USA"},{"companyname":"www.dhl.com","sitecode":"DHLTXUSA-4","siteaddress":"2221 Canada Dry St Houston USA"},{"companyname":"www.dhl.com","sitecode":"DHLNYUSA-5","siteaddress":"521 5th Ave Rm 2130 New York USA"},{"companyname":"www.dhl.com","sitecode":"DHLTXUSA-1","siteaddress":"6505 N Houston Rosslyn Rd Houston USA"},{"companyname":"www.dhl.com","sitecode":"DHLTXUSA-3","siteaddress":"9405 N County Road 2000 Lubbock USA"},{"companyname":"www.dhl.com","sitecode":"DHLNYMEX-10","siteaddress":"One Markin Lane Wyoming USA"},{"companyname":"www.dhl.com","sitecode":"DHLNYUSA-8","siteaddress":"One Markin Lane Wyoming USA"}]},{"partynumber":"UPS","type":"sponsors","sites":[{"companyname":"www.ups.com","sitecode":"UPSTXUSA-3","siteaddress":"1455 West Loop S Houston USA"},{"companyname":"www.ups.com","sitecode":"UPSNYUSA-8","siteaddress":"1050 Hook Rd Farmington USA"},{"companyname":"www.ups.com","sitecode":"UPSNYMEX-10","siteaddress":"1050 Hook Rd Farmington USA"},{"companyname":"www.ups.com","sitecode":"UPSNYUSA-7","siteaddress":"1400 Broadway Fl 2 New York USA"},{"companyname":"www.ups.com","sitecode":"UPSTXUSA-4","siteaddress":"14902 Sommermeyer St Ste 100 Houston USA"},{"companyname":"www.ups.com","sitecode":"UPSNYMEX-9","siteaddress":"1050 Hook Rd Farmington USA"},{"companyname":"www.ups.com","sitecode":"UPSNYUSA-6","siteaddress":"101 Cranbrook Ext Tonawanda USA"},{"companyname":"www.ups.com","sitecode":"UPSNYUSA-5","siteaddress":"290 Barrett Hill Rd Mahopac USA"},{"companyname":"www.ups.com","sitecode":"UPSTXUSA-2","siteaddress":"11308 Midmorning Dr Austin USA"},{"companyname":"www.ups.com","sitecode":"UPSTXUSA-1","siteaddress":"3900 Harrisburg Blvd Houston USA"}]},{"partynumber":"HDEPO","type":"sponsors","sites":[{"companyname":"Home Depot USA.","sitecode":"HDEPOWH","siteaddress":"55031 Hdepo WH Road Bossier City USA"},{"companyname":"www.homeDepot.com","sitecode":"HDEPONYUSA-8","siteaddress":"166 Haverford Rd Hicksville USA"},{"companyname":"www.homeDepot.com","sitecode":"HDEPOTXUSA-4","siteaddress":"4901 Blaffer St Houston USA"},{"companyname":"Home Depot USA.","sitecode":"HDEPOHQ","siteaddress":"5031 Hdepo HQ Road Bossier City USA"},{"companyname":"www.homeDepot.com","sitecode":"HDEPONYMEX-9","siteaddress":"166 Haverford Rd Hicksville USA"},{"companyname":"www.homeDepot.com","sitecode":"HDEPONYUSA-6","siteaddress":"1790 Broadway Ste 702 New York USA"},{"companyname":"www.homeDepot.com","sitecode":"HDEPOTXUSA-3","siteaddress":"2203 Timberloch Pl Ste 252 The Woodlands USA"},{"companyname":"www.homeDepot.com","sitecode":"HDEPONYMEX-10","siteaddress":"166 Haverford Rd Hicksville USA"},{"companyname":"www.homeDepot.com","sitecode":"HDEPONYUSA-5","siteaddress":"1040 Avenue Of The Americas New York USA"},{"companyname":"Home Depot USA.","sitecode":"HDEPOMO","siteaddress":"5031 Hdepo MO Road Bossier City USA"},{"companyname":"www.homeDepot.com","sitecode":"HDEPOTXUSA-1","siteaddress":"14603 Chrisman Rd Houston USA"},{"companyname":"www.homeDepot.com","sitecode":"HDEPOTXUSA-2","siteaddress":"16103 University Oak San Antonio USA"},{"companyname":"www.homeDepot.com","sitecode":"HDEPONYUSA-7","siteaddress":"392 Pulteney St Corning USA"}]},{"partynumber":"GWILL","type":"sponsors","sites":[{"companyname":"www.goodwillconstruct.com","sitecode":"GWILLNYMEX-9","siteaddress":"3300 Northern Blvd Fl 2 Long Island City USA"},{"companyname":"GoodWill Supplies and Construction","sitecode":"GWILLHQ","siteaddress":"543, Light Ray Street Wellknown city In"},{"companyname":"www.goodwillconstruct.com","sitecode":"GWILLNYMEX-10","siteaddress":"3300 Northern Blvd Fl 2 Long Island City USA"},{"companyname":"www.goodwillconstruct.com","sitecode":"GWILLNYUSA-7","siteaddress":"1800 New Hwy Farmingdale USA"},{"companyname":"www.goodwillconstruct.com","sitecode":"GWILLNYUSA-8","siteaddress":"3300 Northern Blvd Fl 2 Long Island City USA"},{"companyname":"GoodWill Supplies and Construction","sitecode":"GWILLMO","siteaddress":"6789, Engineering Laner Large city GBR"},{"companyname":"www.goodwillconstruct.com","sitecode":"GWILLTXUSA-2","siteaddress":"945 McKinney St # 237 Houston USA"},{"companyname":"www.goodwillconstruct.com","sitecode":"GWILLNYUSA-6","siteaddress":"580 Broadway Menands USA"},{"companyname":"www.goodwillconstruct.com","sitecode":"GWILLTXUSA-3","siteaddress":"6921 Olson Ln Pasadena USA"},{"companyname":"www.goodwillconstruct.com","sitecode":"GWILLTXUSA-1","siteaddress":"7075 Ranch Road 2338 Georgetown USA"},{"companyname":"www.goodwillconstruct.com","sitecode":"GWILLTXUSA-4","siteaddress":"3839 Dilido Rd Dallas USA"},{"companyname":"www.goodwillconstruct.com","sitecode":"GWILLNYUSA-5","siteaddress":"1 Radisson Plz Ste 803 New Rochelle USA"},{"companyname":"GoodWill Supplies and Construction","sitecode":"GWILLHQ","siteaddress":"543, Light Ray Street Wellknown city USA"},{"companyname":"GoodWill Supplies and Construction","sitecode":"GWILLWH","siteaddress":"2345, Well formed lane Hope in city USA"}]},{"partynumber":"FEDEX","type":"sponsors","sites":[{"companyname":"www.fedex.com","sitecode":"FEDEXTXUSA-2","siteaddress":"400 Langford St Clint USA"},{"companyname":"www.fedex.com","sitecode":"FEDEXNYUSA-8","siteaddress":"3736 Kellogg Rd Cortland USA"},{"companyname":"www.fedex.com","sitecode":"FEDEXTXUSA-4","siteaddress":"5025 East Business 20 Abilene USA"},{"companyname":"www.fedex.com","sitecode":"FEDEXNYUSA-5","siteaddress":"637 New Loudon Rd Ste 2 Latham USA"},{"companyname":"Fedex USA.","sitecode":"FEDEXWH","siteaddress":"6754 Fedex WH Road Fedex City USA"},{"companyname":"www.fedex.com","sitecode":"FEDEXTXUSA-1","siteaddress":"4305 N Interstate 35 Denton USA"},{"companyname":"Fedex USA.","sitecode":"FEDEXHQ","siteaddress":"7800 Fedex HQ Road Bossier City USA"},{"companyname":"www.fedex.com","sitecode":"FEDEXTXUSA-3","siteaddress":"14444 Stuebner Airline Rd Houston USA"},{"companyname":"www.fedex.com","sitecode":"FEDEXNYMEX-10","siteaddress":"3736 Kellogg Rd Cortland USA"},{"companyname":"www.fedex.com","sitecode":"FEDEXNYUSA-7","siteaddress":"65 Old Indian Rd Milton USA"},{"companyname":"www.fedex.com","sitecode":"FEDEXNYMEX-9","siteaddress":"3736 Kellogg Rd Cortland USA"},{"companyname":"Fedex USA.","sitecode":"FEDEXMO","siteaddress":"9600 Fedex MO Road Bossier City USA"},{"companyname":"www.fedex.com","sitecode":"FEDEXNYUSA-6","siteaddress":"1254 Erie Ave North Tonawanda USA"}]}]}}</return> 
     </ns2:LoginResponse> 
    </soap:Body> 
</soap:Envelope> 

,但沒能得到與我的代碼正確應對完成之前和正在發生錯誤,正如我在我的問題中所描述的那樣。

我對上述問題的解決方案:

首先,我做了一個txt file同樣喜歡SOAP請求與{%key%}無論你想添加的參數進行動態。使這個txt文件並把它放到raw文件夾中創建res文件夾。現在你將有yourfilename.txt如看起來象下面這樣:

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:test="http://test.login/"> 
    <soapenv:Header/> 
    <soapenv:Body> 
     <test:Login> 
     <!--Optional:--> 
     <arg0>{%arg0%}</arg0> 
     <!--Optional:--> 
     <arg1>{%arg1%}</arg1> 
     <!--Optional:--> 
     <arg2>{%arg2%}</arg2> 
     </test:Login> 
    </soapenv:Body> 
</soapenv:Envelope> 

,現在你會做代碼像下面你的java文件訪問正確的反應中:

你會得到響應與調用下面的方法:

response = new sendSoapRequest(
         getApplicationContext(), yourargument1, yourargument2, yourargument3); 

與包含如下方法:

/** 
    * Sends SOAP request to the web service. 
    * 
    * @param requestContent 
    *   the SOAP request XML 
    * @return KvmSerializable object generated from the SOAP response XML 
    * @throws Exception 
    *    if the web service can not be reached, or the response data 
    *    can not be processed. 
    */ 
    public String sendSoapRequest(Context c, String arg0, String arg1, 
      String arg2) throws Exception { 


URL = "PASTE YOUR WS URL";//"http://test.tpsynergy.com:8080/tpsynergy/services/login"; 
     String FinalString = getStringFromRaw(c); 
     Log.i("TAG", "*********************** FinalString Before " 
       + FinalString); 

     FinalString = getFinalString(FinalString, arg0, arg1, arg2); 

     Log.i("TAG", "***********************After Finallyyy : FinalString " 
       + FinalString); 

     // send SOAP request 
     InputStream responseIs = sendRequest(FinalString); 

     // create the response SOAP envelope 
     SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(
       SoapEnvelope.VER11); 

     // process SOAP response 
     parseResponse(responseIs, envelope); 

     Object bodyIn = envelope.bodyIn; 

     SoapObject resultsRequestSOAP = (SoapObject) envelope.bodyIn; 
     String response = resultsRequestSOAP.getProperty(0).toString(); 

     Log.i(" Login Webservice Response", 
       "Responce ---->" + response.toString()); 

     // 

     if (bodyIn instanceof SoapFault) { 
      throw (SoapFault) bodyIn; 
     } 

     return response.toString(); 
    } 

    public String getFinalString(String ABC, String arg0, String arg1, 
      String arg2) { 
     // parse the template and replace all keywords 

     HashMap<String, String> hashMap = new HashMap<String, String>(); 

     hashMap.put("arg0", arg0); 
     hashMap.put("arg1", arg1); 
     hashMap.put("arg2", arg2); 

     StringBuffer sb = new StringBuffer(); 
     try { 
      // find all keywords 
      Pattern patern = Pattern.compile("\\{%(.*?)%\\}"); 
      Matcher matcher = patern.matcher(ABC); 

      while (matcher.find()) { 
       String keyName = matcher.group(1); 

       Log.i("LOG_TAG", "Key Name" + keyName); 
       String keyValue = hashMap.get(keyName); 
       if (keyValue == null) { 
        keyValue = ""; 
       } 
       // replace the key with value 
       matcher.appendReplacement(sb, keyValue); 
      } 
      matcher.appendTail(sb); 

      // return the final string 
      return sb.toString(); 
     } catch (Throwable e) { 
      Log.e("LOG_TAG", "Error parsing template", e); 
      return null; 
     } 
    } 

    private String getStringFromRaw(Context c) throws IOException { 
     Resources r = c.getResources(); 
     InputStream is; 
     if (MainActivity.PRODUCTION) { 
      Log.i(TAG, "Inside Production Raw File"); 
      is = r.openRawResource(R.raw.logininfoproduction); 
     } else { 
      Log.i(TAG, "Inside Test Raw File"); 
      is = r.openRawResource(R.raw.logininfotest); 
     } 

     String statesText = convertStreamToString(is); 
     is.close(); 
     return statesText; 
    } 

    private String convertStreamToString(InputStream is) throws IOException { 
     ByteArrayOutputStream baos = new ByteArrayOutputStream(); 
     int i = is.read(); 
     while (i != -1) { 
      baos.write(i); 
      i = is.read(); 
     } 
     return baos.toString(); 
    } 

    /** 
    * Sends SOAP request to the web service. 
    * 
    * @param requestContent 
    *   the content of the request 
    * @return {@link InputStream} containing the response content 
    * @throws Exception 
    *    if communication with the web service can not be established, 
    *    or when the response from the service can not be processed. 
    */ 
    private InputStream sendRequest(String requestContent) throws Exception { 

     // initialize HTTP post 
     HttpPost httpPost = null; 

     try { 
      httpPost = new HttpPost(URL); 
      httpPost.addHeader("Accept-Encoding", "gzip,deflate"); 
      httpPost.addHeader("Content-Type", "text/xml;charset=UTF-8"); 
      httpPost.addHeader("SOAPAction", "\"\""); 
     } catch (Throwable e) { 
      Log.e("LOG_TAG", "Error initializing HTTP post for SOAP request", e); 
      // throw e; 
     } 

     // load content to be sent 
     try { 
      HttpEntity postEntity = new StringEntity(requestContent); 
      httpPost.setEntity(postEntity); 
     } catch (UnsupportedEncodingException e) { 
      Log.e("LOG_TAG", 
        "Unsupported ensoding of content for SOAP request", e); 
      throw e; 
     } 

     // send request 
     HttpResponse httpResponse = null; 
     HttpClient httpClient = new DefaultHttpClient(); 
     try { 
      httpResponse = httpClient.execute(httpPost); 
     } catch (Throwable e) { 
      Log.e("LOG_TAG", "Error sending SOAP request", e); 
      // throw e; 
     } 

     // get SOAP response 
     try { 
      // get response code 
      int responseStatusCode = httpResponse.getStatusLine() 
        .getStatusCode(); 

      // if the response code is not 200 - OK, or 500 - Internal error, 
      // then communication error occurred 
      if (responseStatusCode != 200 && responseStatusCode != 500) { 
       String errorMsg = "Got SOAP response code " 
         + responseStatusCode + " " 
         + httpResponse.getStatusLine().getReasonPhrase(); 
       // ... 
      } 

      // get the response content 
      HttpEntity httpEntity = httpResponse.getEntity(); 
      InputStream is = httpEntity.getContent(); 
      return is; 
     } catch (Throwable e) { 
      Log.e("LOG_TAG", "Error getting SOAP response", e); 
      // throw e; 
     } 
     return null; 
    } 

    /** 
    * Parses the input stream from the response into SoapEnvelope object. 
    */ 
    private void parseResponse(InputStream is, SoapEnvelope envelope) 
      throws Exception { 
     try { 
      XmlPullParser xp = new KXmlParser(); 
      xp.setFeature(XmlPullParser.FEATURE_PROCESS_NAMESPACES, true); 
      xp.setInput(is, "UTF-8"); 
      envelope.parse(xp); 
     } catch (Throwable e) { 
      Log.e("LOG_TAG", "Error reading/parsing SOAP response", e); 

     } 

    } 

現在您不必擔心ComplexType請求參數或其他任何事情。 因爲您正在傳遞與XML相同的formate,就像SOAPUI工具正在傳遞一樣。

現在你有了你想要的正確答案。

希望它能起作用。

+0

ü值得+50 bhavesh ..歡呼聲,就你知道「Bahvesh庫馬爾」從電視節目khichdi :))) –

+0

@USER_NAME:Thnks :)是的,我知道你正在談論的性格。 :) –

+0

@BhaveshPatadiya:我需要你的幫助請。參考鏈接:[http://stackoverflow.com/questions/19198017/pass-arraylist-data-into-soap-web-service-in-android](http://stackoverflow.com/questions/19198017/pass-arraylist -data-into-soap-web-service-in-android)任何想法如何將數組數據傳遞給android中的soap服務? –

0

試試這個。

SoapObject respuesta = new SoapObject(NAMESPACE, METHOD_NAME); 
Registro registro = new Registro(); 
registro.nombre = txtprod.getText().toString(); 
registro.codigo = txtcod.getText().toString(); 
respuesta.addProperty("cadena", "si llega"); 

PropertyInfo pi = new PropertyInfo(); 
pi.setName("registro"); 
pi.setValue(registro); 
pi.setType(registro.getClass()); 
respuesta.addProperty(pi); 

final SoapSerializationEnvelope sobre = new SoapSerializationEnvelope(
     SoapEnvelope.VER11); 
//sobre.bodyOut;`` 
//sobre.implicitTypes=true; 
sobre.dotNet = true; 
//sobre.setAddAdornments(false); 
sobre.setOutputSoapObject(respuesta); 
//sobre.bodyIn=respuesta; 
sobre.addMapping(NAMESPACE, "Registro", registro.getClass()); 
try 
{ 
    HttpTransportSE transporte = new HttpTransportSE(URL, timeout); 
    //transporte.debug = true; 
    transporte.call(SOAP_ACTION, sobre); 


     SoapPrimitive resultado_xml = (SoapPrimitive)sobre.getResponse(); 
     Log.e("valor de response", resultado_xml.toString()); 
        int res = Integer.parseInt(resultado_xml.toString()); 

    if(res == 1) 

    { 
     Log.e("entra al if", "lelel"); 

    } 
} 
catch(IOException e) 
{ 
    e.printStackTrace(); 
    result = false; 
}catch(XmlPullParserException e) 
{ 
    e.printStackTrace(); 
    result = false; 
} 
return result; 

} 
+0

請不要發佈只是代碼只有答案。請詳細說明正在做什麼。 – NathanOliver