Android Ksoap2 and WCF
<p>I have developed a WCF Service .NET4 (SOAP) and I am trying to <strong>upload files</strong> from Android. 
With .NET client work fine, but with Android wont work, below code I am using in Android.</p>

<p>the the WCF service recive the data, the stream seems to be empty (zero length).</p>

<p>Please help me.</p>

<pre><code>public class WCFclient {
private static final String METHOD_NAME = "UploadFile";
private static final String NAMESPACE = "http://tempuri.org/";
private static final String URL = "http://192.168.1.103/AndroidWCF/Service1.svc";
private static final String SOAP_ACTION = "http://tempuri.org/ITransferService/UploadFile";



public static String extractText(byte[] _data)

{
    @SuppressWarnings("unused")
    int lun = _data.length;

     SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME);
  MarshalBase64 marshal = new MarshalBase64();
     PropertyInfo p1=new PropertyInfo();
     p1.setName("request");
     p1.setType(_data);
     request.addProperty(p1);
     SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
     envelope.dotNet=true;
     envelope.encodingStyle = SoapSerializationEnvelope.XSD;
     envelope.setOutputSoapObject(request);
       marshal.register(envelope);
     HttpTransportSE androidHttpTransport = new HttpTransportSE(URL, 20000);


     try {
        androidHttpTransport.call(SOAP_ACTION, envelope);
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (XmlPullParserException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } 
     SoapObject result = null;
    try {
        result = (SoapObject)envelope.getResponse(); 
    } catch (SoapFault e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
     String resultData=result.getProperty(0).toString();
    return resultData;

}

// Returns the contents of the file in a byte array.
    public static byte[] getBytesFromFile(File file) throws IOException {
        InputStream is = new FileInputStream(file);

        // Get the size of the file
        long length = file.length();

        // You cannot create an array using a long type.
        // It needs to be an int type.
        // Before converting to an int type, check
        // to ensure that file is not larger than Integer.MAX_VALUE.
        if (length &gt; Integer.MAX_VALUE) {
            // File is too large
        }

        // Create the byte array to hold the data
        byte[] bytes = new byte[(int)length];

        // Read in the bytes
        int offset = 0;
        int numRead = 0;
        while (offset &lt; bytes.length
               &amp;&amp; (numRead=is.read(bytes, offset, bytes.length-offset)) &gt;= 0) {
            offset += numRead;
        }

        // Ensure all the bytes have been read in
        if (offset &lt; bytes.length) {
            throw new IOException("Could not completely read file "+file.getName());
        }

        // Close the input stream and return bytes
        is.close();
        return bytes;
    }
</code></pre>

<p>}</p>

<p>The error happened in the WCF service, exception is: "Start element 'request' from namespace 'http://tempuri.org/' expected. Found element 'image' from namespace 'http://tempuri.org/'. Line 1, position 304."</p>

<pre><code> Public Sub UploadFile(request As Stream) Implements ITransferService.UploadFile


    Dim writeStream As FileStream = New FileStream("c:\" &amp; Now.Ticks.ToString &amp; ".bmp", FileMode.Create, FileAccess.Write)
    ReadWriteStream(request, writeStream)


End Sub

Private Sub ReadWriteStream(readStream As Stream, writeStream As Stream)
    Dim Length As Integer = 256
    Dim buffer As [Byte]() = New [Byte](Length - 1) {}
    Dim bytesRead As Integer = readStream.Read(buffer, 0, Length)
    ' write the required bytes
    While bytesRead &gt; 0
        writeStream.Write(buffer, 0, bytesRead)
        bytesRead = readStream.Read(buffer, 0, Length)
    End While
    readStream.Close()
    writeStream.Close()
End Sub
</code></pre>
