2011-08-09 34 views
4

幫助我,我在它上面搜索整個www大約3周,不能使它工作!Android,Ksoap,網絡服務

我有一個WS,只是想讓我的應用程序有響應。但我後,正確的一切不幸總是得到以下錯誤!

08-09 15:29:30.930: INFO/System.out(1800): That is the bodyin envelope: SoapFault - Faultcode: 'env:Server' 
faultstring: 'javax.xml.bind.UnmarshalException: unexpected element (uri:"", local:"Apgame"). 
Expected elements are 
<{http://master.system.com.br/}Apgame>, 
<{http://master.system.com.br/}numberSerie>, 
<{http://master.system.com.br/}idPost>, 
faultactor: 'null' detail: null 

我的應用正在使用這個。

private void getSOAPRequest() { 
     //no matter what I put here in SOAP_ACTION it makes no difference 
     String SOAP_ACTION = "http://master.system.com.br/"; 
     String NAMESPACE = "http://system.com.br/"; 
     String METHOD_NAME = "GetPrice"; 
     String URL = "http://12.12.12.111/MasterWS/GetPrice?WSDL"; 

     SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME); 
     request.addProperty("Apgame", "8"); 
     request.addProperty("numberSerie", "31345"); 
     request.addProperty("idPost", "4"); 

     SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11); 
     envelope.setOutputSoapObject(request); 

     HttpTransportSE androidHttpTransport = new HttpTransportSE(URL); 
     try { androidHttpTransport.call(SOAP_ACTION, envelope); 
     } catch (IOException e) { 
     e.printStackTrace(); 
     } catch (XmlPullParserException e) { 
     e.printStackTrace();} 
     System.out.println("That is the bodyin envelope: "+ envelope.bodyIn); 
} 

我有SOAP用戶界面,我可以打電話給WS真的沒有問題。

<soapenv:Envelope 
xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" 
xmlns:tran="http://master.system.com.br/" 
xmlns:ws="http://system.com.br/"> 
    <soapenv:Body> 
     <ws:GetPrice> 
     <tran:Apgame>8</tran:Apgame> 
     <tran:numberSerie>31345</tran:numberSerie> 
     <tran:idPost>4</tran:idPost> 
     </ws:GetPrice> 
    </soapenv:Body> 
</soapenv:Envelope> 

我已經嘗試了不同的Ksoap庫,不同的名稱空間,method_name。不同的SoapEnvelope.VER。我不記得我測試過的所有東西。我很絕望。

太感謝你了..

回答

0

您必須爲每個屬性提供名稱空間。嘗試addProperty的超負荷版本,並設置PropertyInfo包含namenamespace爲每個屬性。

喜歡的東西:

String TRAN_NAMESPACE = "http://master.system.com.br/"; 
... 

SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME); 
PropertyInfo apGame = new PropertyInfo(); 
apGame.name = "Apgame"; 
apGame.namespace = TRAN_NAMESPACE; 
request.addProperty(apGame, "8"); 
... 
+1

謝謝你的傢伙!有效! Eclipse說:「方法addProperty(PropertyInfo,Object)已被棄用」 還有另一種方法嗎? 也許只用一個PropertyInfo和Namespace? 你剛剛幫了我很多! –

+0

我支持'Jr'問的問題。如果有其他任何方法請告訴我們 – faisal1208

0

做這樣的:

String SOAP_ACTION = "http://master.system.com.br/"; 
    String NAMESPACE = "http://system.com.br/"; 
    String METHOD_NAME = "GetPrice"; 
    String URL = "http://12.12.12.111/MasterWS/GetPrice?WSDL"; 

    SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME); 
    request.addProperty("Apgame", "8"); 
    request.addProperty("numberSerie", "31345"); 
    request.addProperty("idPost", "4"); 

    SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11); 
    envelope.dotNet=true; 
    envelope.setOutputSoapObject(request); 
    try 
    {    

    HttpTransportSE androidHttpTransport = new HttpTransportSE(URL); 
    androidHttpTransport.call(SOAP_ACTION, envelope); 

    SoapPrimitive result = (SoapPrimitive)envelope.getResponse(); 
    } 
    catch (Exception e) 
    { 

    } 

如果你的開放的變量是正確這應該做的伎倆。

+0

@Jannik嗨! 隨着你的提示,我可以選擇在我的回覆中設置的uri,所以它幫了我很多,但它把錯誤的命名空間看到.. 08-10 09:14:12.488:INFO/System.out(362):SoapFault - faultcode:'env:Server'faultstring:'javax.xml.bind.UnmarshalException:意外元素(uri:「http://system.com.br/」,local:「Apgame」)。預期的元素是<{http://master.system.com.br/} Apgame>,...'faultactor:'null'詳細信息:null 你知道嗎?謝謝! –

+0

ops,如果我改變了**命名空間x soap_Action **我得到了。 08-10 09:15:33.488:INFO/System.out(392):SoapFault - faultcode:'env:Client'faultstring:'Endpoint {http://system.com.br/}GetPriceWSPortType不包含操作元數據爲:{http://trans.system.com.br//}GetPrice'faultactor:'null'detail:null –