1

我正在使用 wcf rest 服务从 android 上传文件。我创建了一个如下所示的服务,我想从 android 发送文件名和文件体,但我无法从 android 发送文件名和文件体。

WCF 休息服务:

 public interface IService1
    {

        [WebInvoke(Method = "POST", UriTemplate = "upload")]
        // string PostImage(Stream stream);
        string PostImage(ResponseFile file);
    }

    [MessageContract]
    public class ResponseFile : IDisposable
    {
        [MessageHeader]
        public string Filename;

        [MessageBodyMember]
        public System.IO.Stream FileByteStream;

        public void Dispose()
        {
            if (FileByteStream != null)
            {
                FileByteStream.Close();
                FileByteStream = null;
            }
        }
    }

使用 wcf 休息服务的 Android 代码:

  httppost = new HttpPost("http://192.168.2.34/Service1.svc/upload");
                        HttpParams httpParameters = new BasicHttpParams();
                        HttpConnectionParams.setConnectionTimeout(httpParameters, 9000000);
                        HttpConnectionParams.setSoTimeout(httpParameters, 9000000);
                        DefaultHttpClient httpclient = new DefaultHttpClient(httpParameters);
                        InputStreamEntity reqEntity = new InputStreamEntity(
                                new FileInputStream(new File(picturePath)), -1);


                        reqEntity.setContentType("binary/octet-stream");
                        reqEntity.setChunked(true); // Send in multiple parts if needed

                       httppost.setHeader("Filename", picturePath);
                        httppost.setEntity(reqEntity);
                        response = httpclient.execute(httppost);    

我如何从android客户端设置messageheader和messagebody。你能帮我解决这个问题吗?以及如何查询从服务器到安卓客户端的内容范围。

4

0 回答 0