Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7564217
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T13:51:24+00:00 2026-05-30T13:51:24+00:00

I’m trying to upload a file from Android (2.3.4) using the below code, I

  • 0

I’m trying to upload a file from Android (2.3.4) using the below code, I understand I must use multipart post if I want to send parameter as well. This is my Android code:

public void uploadFile(File uploadFile) {
    HttpClient httpClient = new DefaultHttpClient();

    HttpPost postRequest = new HttpPost("http://192.168.0.102/application/services/sendfile/");
    ResponseHandler<String> responseHandler = new BasicResponseHandler();

    // Indicate that this information comes in parts (text and file)
    MultipartEntity reqEntity = new MultipartEntity(HttpMultipartMode.BROWSER_COMPATIBLE);

try {

    //Create a JSON object to be used in the StringBody
    JSONObject jsonObj = new JSONObject();

    //Add some values
    jsonObj.put("filename", uploadFile.getName());

    //Add the JSON "part"
    reqEntity.addPart("entity", new StringBody(jsonObj.toString()));
}
catch (JSONException e) {
    Log.v("App", e.getMessage());
}
catch (UnsupportedEncodingException e) {
    Log.v("App", e.getMessage());
}

FileBody fileBody = new FileBody(uploadFile);//, "application/octet-stream");
    reqEntity.addPart("file", fileBody);

    try {
        postRequest.setEntity(reqEntity);

         //Execute the request "POST"
    HttpResponse httpResp = httpClient.execute(postRequest);

    //Check the status code, in this case "created"
    if(((HttpResponse) response).getStatusLine().getStatusCode() == HttpStatus.SC_CREATED){
        Log.v("App","Created");
    }
    } catch (UnsupportedEncodingException e) {
        e.printStackTrace();
    } catch (ClientProtocolException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    }
}

It’s always retrieving bad request.

On the other side I have a WCF REST service made using Template 40:

[WebInvoke(
            Method = "POST",
            UriTemplate = "sendFile",
            BodyStyle = WebMessageBodyStyle.Wrapped)]
         public int sendFile(Stream receivedFile)
        {
           // How should I process the multipart file here to save it with its name on disk?
        }

I have this in my web.config

  <system.webServer>
        <modules runAllManagedModulesForAllRequests="true">
            <remove name="WebDAVModule" />
            <add name="UrlRoutingModule" type="System.Web.Routing.UrlRoutingModule, System.Web, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
        </modules>
        <directoryBrowse enabled="false" />
    </system.webServer>

    <system.serviceModel>
        <serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true" />
        <standardEndpoints>
            <webHttpEndpoint>
                <!--
            Configure the WCF REST service base address via the global.asax.cs file and the default endpoint
            via the attributes on the <standardEndpoint> element below
        -->
                <standardEndpoint name="" helpEnabled="true" automaticFormatSelectionEnabled="true" />
            </webHttpEndpoint>
        </standardEndpoints>
    </system.serviceModel>

and this in my global.asax

private void RegisterRoutes()
        {
            RouteTable.Routes.Add(new ServiceRoute("Service", new WebServiceHostFactory(), typeof(AccidentService)));
        }

Any idea why the WCF doesn’t receive the file if I put a breakpoint in it?

If anyone has a better example on how to send a file from Android (2.3.4) to WCF 4.0 will be really appreciated.

Thanks in advance! Guillermo.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-30T13:51:24+00:00Added an answer on May 30, 2026 at 1:51 pm

    The problem was with the bindings in the WCF! changing them made it work!

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to understand how to use SyndicationItem to display feed which is
I want use html5's new tag to play a wav file (currently only supported
We are using XSLT to translate a RIXML file to XML. Our RIXML contains
i want to parse a xhtml file and display in UITableView. what is the
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
Does anyone know how can I replace this 2 symbol below from the string
I'm trying to use string.replace('’','') to replace the dreaded weird single-quote character: ’ (aka
I'm trying to create an if statement in PHP that prevents a single post
I am using Paperclip to handle profile photo uploads in my app. They upload
Basically, what I'm trying to create is a page of div tags, each has

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.