将图像和文本从android发送到wcf服务

时间:2015-06-21 08:55:18

标签: android wcf upload

我正在尝试将图片和文字上传到wcf服务。我创建了一个保存上传图像的服务:

                <OperationContract()> _
                <WebGet(UriTemplate:="UploadFile",      
    BodyStyle:=WebMessageBodyStyle.Wrapped)>
     Function UploadFile(ByVal fileStream As Stream)

uploadFile函数是这样的:

   Function UploadFile(ByVal fileStream As Stream) Implements      IServiceApp.UploadFile
    Dim FilePath As String = Hosting.HostingEnvironment.MapPath("~/fh/adds")

    Dim fileToupload As FileStream = New FileStream(IO.Path.Combine(FilePath, "fass.png"), FileMode.Create)

    Dim bytearray(8192) As Byte

    Dim bytesRead As Integer, totalBytesRead As Integer = 0
    Do
        bytesRead = fileStream.Read(bytearray, 0, bytearray.Length)
        totalBytesRead += bytesRead
      fileToupload.Write(bytearray, 0, bytearray.Length)
    Loop While bytesRead > 0


    fileToupload.Close()
    fileToupload.Dispose()
End Function

此外,我将用于将图像发送到服务器的android代码位于:

     File file = new    
            File(Environment.getExternalStorageDirectory().getAbsolutePath(),
                        "temp_photo.jpg");
             Log.d("errrr", "1");
              try {
                    HttpClient httpclient = new DefaultHttpClient();

                    HttpPost httppost = new HttpPost("http://www.****.com/ServiceApp.svc/UploadFile()");
                    Log.d("errrr", "2");
                    InputStreamEntity reqEntity = new InputStreamEntity(
                            new FileInputStream(file), -1);
                    Log.d("errrr", "3");
                    reqEntity.setContentType("binary/octet-stream");
                    Log.d("errrr", "4");
                    reqEntity.setChunked(true); // Send in multiple parts if needed
                    Log.d("errrr", file.getPath());
                    httppost.setEntity(reqEntity);
                    Log.d("errrr", "6");
                    HttpResponse response = httpclient.execute(httppost);

                    //Do something with response...

                } catch (Exception e) {
                    // show error
                    Toast.makeText(c, e.getMessage(), Toast.LENGTH_LONG).show();
                }

但是当我运行应用程序时,没有任何内容保存在服务器中,也没有显示为toast错误消息。 问题出在哪儿?我也使用了webhttpbinding。

0 个答案:

没有答案