开发者

Sending Complex Objects, Attachments with ksoap2-Android

I'm using ksoap2-Android on an Android project to upload a file. It's not working.

First of all, my wsdl looks like this:

<xsd:element name="Op1RequestType">
    <xsd:complexType>
        <xsd:sequence>
            <xsd:element name="date" type="xsd:dateTime"/>
            <xsd:element maxOccurs="unbounded" minOccurs="0" name="imgFile" 
                type="tns:Attachment"/>
        </xsd:sequence>
    </xsd:complexType>
</xsd:element>

And "tns:Attachment" is defined like this:

<xsd:complexType name="Attachment">
    <xsd:sequence>
        <xsd:element name="file" type="xsd:base64Binary"/>
        <xsd:element name="filename" type="xsd:string"/>
    </xsd:sequence>
</xsd:complexType>

I'm creating a SoapSerializationEnvelope and adding in the property with name date and the value as the string representation of the current date. This works successfully, even if I don't add a file (note the minOccurs="0"). However, when I try to add a file, it fails horribly:

First, I make a representative of the Attachment type by creating a SoapObject which has the properties file and filename, of types byte[].class and String.class respectively.

Then I add these objects to a generic Vector (to represent the multiplicity of the imgFile item) and attach the Vector as a property to the envelope. This creates a SOA开发者_开发百科P message successfully, and the response from the server raises an exception (because it's an error message, instead of a proper response, because somehow my input isn't good...):

WARN/System.err(438): SoapFault - faultcode: 'soapenv:Server' 
faultstring:'org.apache.axis2.databinding.ADBException: Unexpected subelement imgFile'
faultactor: 'null' detail: org.kxml2.kdom.Node@4676b8a0

Okay, so what am I doing wrong? Is there a way to see the request SOAP envelope that I am sending?


I can see the request SOAP envelope by calling getRequest() on the SoapSerializationEnvelope. This allowed me to see that the vector object actually places each (file, filename) pair into an <item></item> tag, which broke the format. I now am inserting multiple items in succession as the wsdl demands.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜