2013-12-13 127 views
0

我正在做一個使用kso​​ap2的移動應用程序使用web服務。無法將ComplexType對象從ksoap2發送到soap webservice for android

到目前爲止,我能夠通過包含字符串的Web服務發送複雜的對象,雙打,INT,等等

然後,我是能夠通過網絡發送的字節數組。現在我的問題:

當我嘗試創建一個對象通過網絡發送時,其中一個參數是字節數組我從服務器獲取故障字符串。

web服務我正在訪問具有以下WSDL文件:

<wsdl:definitions xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns:ns1="http://org.apache.axis2/xsd" xmlns:ns="http://sensors.components" xmlns:wsaw="http://www.w3.org/2006/05/addressing/wsdl" xmlns:http="http://schemas.xmlsoap.org/wsdl/http/" xmlns:ax21="http://sensors.components/xsd" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:mime="http://schemas.xmlsoap.org/wsdl/mime/" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:soap12="http://schemas.xmlsoap.org/wsdl/soap12/" targetNamespace="http://sensors.components"> 
<wsdl:types> 
<xs:schema attributeFormDefault="qualified" elementFormDefault="qualified" targetNamespace="http://sensors.components/xsd"> 
<xs:complexType name="Pic"> 
<xs:sequence> 
<xs:element minOccurs="0" name="accuracy" type="xs:double"/> 
<xs:element minOccurs="0" name="imageInByte" nillable="true" type="xs:base64Binary"/> 
<xs:element minOccurs="0" name="latitude" type="xs:double"/> 
<xs:element minOccurs="0" name="longitude" type="xs:double"/> 
<xs:element minOccurs="0" name="name" nillable="true" type="xs:string"/> 
<xs:element minOccurs="0" name="time" type="xs:long"/> 
</xs:sequence> 
</xs:complexType> 
</xs:schema> 
<xs:schema xmlns:ax22="http://sensors.components/xsd" attributeFormDefault="qualified" elementFormDefault="qualified" targetNamespace="http://sensors.components"> 
<xs:import namespace="http://sensors.components/xsd"/> 
<xs:element name="pictureWebservice"> 
<xs:complexType> 
<xs:sequence> 
<xs:element minOccurs="0" name="args0" nillable="true" type="ax21:Pic"/> 
</xs:sequence> 
</xs:complexType> 
</xs:element> 
<xs:element name="pictureWebserviceResponse"> 
<xs:complexType> 
<xs:sequence> 
<xs:element minOccurs="0" name="return" nillable="true" type="xs:string"/> 
</xs:sequence> 
</xs:complexType> 
</xs:element> 
</xs:schema> 
</wsdl:types> 
<wsdl:message name="pictureWebserviceRequest"> 
<wsdl:part name="parameters" element="ns:pictureWebservice"/> 
</wsdl:message> 
<wsdl:message name="pictureWebserviceResponse"> 
<wsdl:part name="parameters" element="ns:pictureWebserviceResponse"/> 
</wsdl:message> 
<wsdl:portType name="PictureWSPortType"> 
<wsdl:operation name="pictureWebservice"> 
<wsdl:input message="ns:pictureWebserviceRequest" wsaw:Action="urn:pictureWebservice"/> 
<wsdl:output message="ns:pictureWebserviceResponse" wsaw:Action="urn:pictureWebserviceResponse"/> 
</wsdl:operation> 
</wsdl:portType> 
<wsdl:binding name="PictureWSSoap11Binding" type="ns:PictureWSPortType"> 
<soap:binding transport="http://schemas.xmlsoap.org/soap/http" style="document"/> 
<wsdl:operation name="pictureWebservice"> 
<soap:operation soapAction="urn:pictureWebservice" style="document"/> 
<wsdl:input> 
<soap:body use="literal"/> 
</wsdl:input> 
<wsdl:output> 
<soap:body use="literal"/> 
</wsdl:output> 
</wsdl:operation> 
</wsdl:binding> 
<wsdl:binding name="PictureWSSoap12Binding" type="ns:PictureWSPortType"> 
<soap12:binding transport="http://schemas.xmlsoap.org/soap/http" style="document"/> 
<wsdl:operation name="pictureWebservice"> 
<soap12:operation soapAction="urn:pictureWebservice" style="document"/> 
<wsdl:input> 
<soap12:body use="literal"/> 
</wsdl:input> 
<wsdl:output> 
<soap12:body use="literal"/> 
</wsdl:output> 
</wsdl:operation> 
</wsdl:binding> 
<wsdl:binding name="PictureWSHttpBinding" type="ns:PictureWSPortType"> 
<http:binding verb="POST"/> 
<wsdl:operation name="pictureWebservice"> 
<http:operation location="pictureWebservice"/> 
<wsdl:input> 
<mime:content type="application/xml" part="parameters"/> 
</wsdl:input> 
<wsdl:output> 
<mime:content type="application/xml" part="parameters"/> 
</wsdl:output> 
</wsdl:operation> 
</wsdl:binding> 
<wsdl:service name="PictureWS"> 
<wsdl:port name="PictureWSHttpSoap11Endpoint" binding="ns:PictureWSSoap11Binding"> 
<soap:address location="http://accessible-serv.lasige.di.fc.ul.pt:8181/axis2/services/PictureWS.PictureWSHttpSoap11Endpoint/"/> 
</wsdl:port> 
<wsdl:port name="PictureWSHttpSoap12Endpoint" binding="ns:PictureWSSoap12Binding"> 
<soap12:address location="http://accessible-serv.lasige.di.fc.ul.pt:8181/axis2/services/PictureWS.PictureWSHttpSoap12Endpoint/"/> 
</wsdl:port> 
<wsdl:port name="PictureWSHttpEndpoint" binding="ns:PictureWSHttpBinding"> 
<http:address location="http://accessible-serv.lasige.di.fc.ul.pt:8181/axis2/services/PictureWS.PictureWSHttpEndpoint/"/> 
</wsdl:port> 
</wsdl:service> 
</wsdl:definitions> 

我試圖發送的對象如下:

public class Pic implements KvmSerializable{ 

    private double latitude; 
    private double longitude; 
    private long time; 
    private double accuracy; 
    private String name; 
    private byte[] imageInByte; 

    public byte[] getImageInByte() { 
     return imageInByte; 
    } 
    public void setImageInByte(byte[] imageInByte) { 
     this.imageInByte = imageInByte; 
    } 
    public String getName() { 
     return name; 
    } 
    public void setName(String name) { 
     this.name = name; 
    } 
    public double getLatitude() { 
     return latitude; 
    } 
    public void setLatitude(double latitude) { 
     this.latitude = latitude; 
    } 
    public double getLongitude() { 
     return longitude; 
    } 
    public void setLongitude(double longitude) { 
     this.longitude = longitude; 
    } 
    public double getAccuracy() { 
     return accuracy; 
    } 
    public void setAccuracy(double accuracy) { 
     this.accuracy = accuracy; 
    } 
    public long getTime() { 
     return time; 
    } 
    public void setTime(long time) { 
     this.time = time; 
    } 

    @Override 
    public Object getProperty(int arg0) { 
     switch(arg0){ 
     case 0: 
      return latitude; 
     case 1: 
      return longitude; 
     case 2: 
      return time; 
     case 3: 
      return accuracy; 
     case 4: 
      return name; 
     case 5: 
      return imageInByte; 
     } 
     return null; 
    } 
    @Override 
    public int getPropertyCount() { 
     return 6; 
    } 
    @Override 
    public void getPropertyInfo(int arg0, Hashtable arg1, PropertyInfo arg2) { 
     switch(arg0){ 
     case 0: 
      arg2.type = PropertyInfo.STRING_CLASS; 
      arg2.name = "latitude"; 
      break; 
     case 1: 
      arg2.type = PropertyInfo.STRING_CLASS; 
      arg2.name = "longitude"; 
      break; 
     case 2: 
      arg2.type = PropertyInfo.LONG_CLASS; 
      arg2.name = "time"; 
      break; 
     case 3: 
      arg2.type = Double.class; 
      arg2.name = "accuracy"; 
      break; 
     case 4: 
      arg2.type = PropertyInfo.STRING_CLASS; 
      arg2.name = "name"; 
      break; 
     case 5: 
      arg2.type = MarshalBase64.BYTE_ARRAY_CLASS; 
      arg2.name = "imageInBytes"; 
     default: 
      break; 
     } 
    } 
    @Override 
    public void setProperty(int arg0, Object arg1) { 
     // TODO Auto-generated method stub 
     switch(arg0){ 
     case 0: 
      latitude = Double.parseDouble(arg1.toString()); 
      break; 
     case 1: 
      longitude = Double.parseDouble(arg1.toString()); 
      break; 
     case 2: 
      time = Long.parseLong(arg1.toString()); 
      break; 
     case 3: 
      accuracy = Double.parseDouble(arg1.toString()); 
      break; 
     case 4: 
      name = arg1.toString(); 
      break; 
     case 5: 
      imageInByte = (byte[])arg1; 
     default: 
      break; 
     } 
    } 

我使用訪問的值Web服務有以下幾種:

命名空間= 「http://sensors.components」 URL = 「http://accessible-serv.lasige.di.fc.ul.pt:8181/axis2/services/PictureWS?wsdl」 SOA P動作=「http://sensors.components/pictureWebservice」 方法名=「pictureWebservice」

然後我使用到了發送給Web服務的代碼如下:

String NAMESPACE = "http://sensors.components/xsd"; 
     try { 
      SoapObject request = new SoapObject(connection.getNAMESPACE(), connection.getMETHOD_NAME()); 

      PropertyInfo object = new PropertyInfo(); 
      object.setName("picture"); 
      object.setValue(picture); 
      object.setType(picture.getClass()); 
      object.setNamespace(NAMESPACE); 
      request.addProperty(object); 

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

      MarshalDouble md = new MarshalDouble(); 
      md.register(envelope); 
      new MarshalBase64().register(envelope); 


      envelope.addMapping(NAMESPACE, "Pic", new Pic().getClass()); 

      HttpTransportSE androidHttpTransport = new HttpTransportSE(
        connection.getURL()); 

      androidHttpTransport.call(connection.getSOAP_ACTION(), envelope); 

      SoapPrimitive response = (SoapPrimitive) envelope.getResponse(); 
      System.out.println("response: " + response.toString()); 
     } catch (Exception e) { 
      e.printStackTrace(); 
     } 

雖然我已經嘗試併成功傳遞對象之前與雙打和註冊他們,並能夠通過byte []我無法傳遞一個複雜的類型與一個字節[]在它作爲參數。

的logcat的錯誤,提出未來:

SoapFault - faultcode: 'soapenv:Server' faultstring: 'Exception occurred while trying to invoke service method pictureWebservice' faultactor: 'null' detail: [email protected] 
12-13 22:26:51.363: W/System.err(5393):  at org.ksoap2.serialization.SoapSerializationEnvelope.parseBody(SoapSerializationEnvelope.java:112) 
12-13 22:26:51.363: W/System.err(5393):  at org.ksoap2.SoapEnvelope.parse(SoapEnvelope.java:137) 
12-13 22:26:51.363: W/System.err(5393):  at org.ksoap2.transport.Transport.parseResponse(Transport.java:63) 
12-13 22:26:51.363: W/System.err(5393):  at org.ksoap2.transport.HttpTransportSE.call(HttpTransportSE.java:100) 
12-13 22:26:51.363: W/System.err(5393):  at memory.aid.webservices.WSClient.WSClientPictureFile(WSClient.java:92) 
12-13 22:26:51.363: W/System.err(5393):  at memory.aid.memoryaid.MemoryAid$1.run(MemoryAid.java:185) 
12-13 22:26:51.363: W/System.err(5393):  at android.os.Handler.handleCallback(Handler.java:615) 
12-13 22:26:51.367: W/System.err(5393):  at android.os.Handler.dispatchMessage(Handler.java:92) 
12-13 22:26:51.367: W/System.err(5393):  at android.os.Looper.loop(Looper.java:137) 
12-13 22:26:51.367: W/System.err(5393):  at android.app.ActivityThread.main(ActivityThread.java:4745) 
12-13 22:26:51.367: W/System.err(5393):  at java.lang.reflect.Method.invokeNative(Native Method) 
12-13 22:26:51.367: W/System.err(5393):  at java.lang.reflect.Method.invoke(Method.java:511) 
12-13 22:26:51.375: W/System.err(5393):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786) 
12-13 22:26:51.375: W/System.err(5393):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553) 
12-13 22:26:51.375: W/System.err(5393):  at dalvik.system.NativeStart.main(Native Method) 

任何人有任何的想法,解決方案或建議?非常感謝你提前。

編輯:

從我可以告訴的問題是,不知何故在服務器的Web服務我在類產品圖調用imageInByte參數爲空。沒有其他參數爲空。名稱,緯度,經度,精度和時間都是有效參數byt imageInByte爲空。爲什麼?請幫助

+0

正在發生的事情是,在web服務的服務器產品圖imageInByte參數爲空。沒有其他參數僅爲null imageInByte。爲什麼?誰能幫我?到目前爲止沒有迴應。 – JoaoFilipeClementeMartins

回答

0

您的WSDL中,您定義了這個領域的「imageInByte」簡單型,這就是爲什麼它給U該錯誤。

將其定義爲複雜類型,包含您試圖傳遞的所有字段。

感謝, ambuj