2013-12-13 2 views
0

Я делаю мобильное приложение, которое с помощью ksoap2 использует веб-службы.Не удается отправить объект ComplexType для soap webservice из ksoap2 для android

До сих пор я был в состоянии послать сложные объекты через веб-сервис, который содержал строку, двойник, INT, и т.д ...

Тогда я был способен послать массив байт через сеть. И теперь возникает моя проблема:

Когда я пытаюсь создать объект для отправки по сети, когда один из параметров представляет собой массив байтов, я получаю ошибку с сервера.

Веб-сервис я доступа имеет следующий 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; 
     } 
    } 

Значения, которые я использую, чтобы получить доступ к веб-службы являются следующие:

имен = "http://sensors.components" URL = "http://accessible-serv.lasige.di.fc.ul.pt:8181/axis2/services/PictureWS?wsdl" SoA р действие = «http://sensors.components/pictureWebservice» имя метода = «pictureWebservice»

Тогда код, я использую, чтобы отправить его через к WebService является следующее:

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(); 
     } 

Хотя я попробовал и успешно передавать объекты прежде чем удваивает и регистрирует их и может передавать байты [], я не могу передать сложный тип с байтом [] внутри него в качестве аргумента.

Ошибка 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) 

Каждый имеет какие-либо идеи, решения или предложения? заранее большое спасибо.

EDIT:

от того, что я могу сказать, проблема в том, что как-то в WebService сервера я звоню параметр imageInByte в классе Pic равна нулю. Ни один другой параметр не равен нулю. Имя, широта, долгота, точность и время - все допустимые параметры byt imageInByte имеет значение null. Зачем? Просьба помочь

+0

То, что происходит в том, что на сервере в веб-службы параметр для Pic imageInByte равна нулю. Другим параметром является только nullInByte. Зачем? Может кто-нибудь мне помочь? ответов пока нет. – JoaoFilipeClementeMartins

ответ

0

В вашем WSDL, вы определили это поле «imageInByte», как простой тип, то почему он дает U эту ошибку.

Определите его как сложный тип, имея все поля, которые вы пытаетесь пройти.

Спасибо, ambuj

 Смежные вопросы

  • Нет связанных вопросов^_^