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 7093197
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T08:24:32+00:00 2026-05-28T08:24:32+00:00

I work with a android device which use a WCF web service. I managed

  • 0

I work with a android device which use a WCF web service.

I managed to get a JSON message from WCF, send a file but I didn’t manage to send POST params to the WCF service. My goal is to have somethink like this (Or get an object and then deserialize the JSON). (User is a complex object composed of basically String and Integer)

[OperationContract]
[WebInvoke(
  Method = "POST",
  RequestFormat = WebMessageFormat.Json,
  ResponseFormat = WebMessageFormat.Json,
  UriTemplate = "interventions")]
public void SendInterventions(List<User> user)
{
}

As explained on http://debugmode.net/2011/05/15/wcf-rest-service-with-josn-data/

I used the HTTP Post code like : http://www.softwarepassion.com/android-series-get-post-and-multipart-post-requests/

My first try was very simple, I wanted to send a simple string post param but it doesn’t work.

HttpClient client = new DefaultHttpClient();
List<NameValuePair> params = new ArrayList<NameValuePair>();
params.add(new BasicNameValuePair("user", "kris"));
UrlEncodedFormEntity ent = new UrlEncodedFormEntity(params, HTTP.UTF_8);

HttpPost post = new HttpPost(url);
post.setEntity(ent);
HttpResponse response = client.execute(post);
HttpEntity resEntity = response.getEntity();

And the .Net code

[OperationContract]
[WebInvoke(
  Method = "POST",
  RequestFormat = WebMessageFormat.Json,
  ResponseFormat = WebMessageFormat.Json,
  UriTemplate = "interventions")]
public void SendInterventions(String user)
{
}

Does someone has a good example or somes tips ?

Regards and thanks

Edit

Well I switch on the error reporting in asp .net wcf.

01-22 11:49:46.800: D/SendInterventions(2049):
<Fault xmlns="http://schemas.microsoft.com/ws/2005/05/envelope/none">
<Code><Value>Receiver</Value>
<Subcode><Value xmlns:a="http://schemas.microsoft.com/net/2005/12/windowscommunicationfoundation/dispatcher">a:InternalServiceFault</Value></Subcode>
</Code><Reason>
<Text xml:lang="fr-FR">Le message entrant a un format inattendu 'Raw'. Les formats de message attendus pour l'opération sont 'Xml'; 'Json'. Un WebContentTypeMapper n'a peut-être pas été configuré sur la liaison. Pour plus d'informations, consultez la documentation relative à WebContentTypeMapper.</Text>
</Reason><Detail><ExceptionDetail xmlns="http://schemas.datacontract.org/2004/07/System.ServiceModel" xmlns:i="http://www.w3.org/2001/XMLSchema-instance"><HelpLink i:nil="true"/><InnerException i:nil="true"/>
<Message>Le message entrant a un format inattendu 'Raw'. Les formats de message attendus pour l'opération sont 'Xml'; 'Json'. Un WebContentTypeMapper n'a peut-être pas été configuré sur la liaison. Pour plus d'informations, consultez la documentation relative à WebContentTypeMapper.</Message>
<StackTrace>   à System.ServiceModel.Dispatcher.DemultiplexingDispatchMessageFormatter.DeserializeRequest(Message message, Object[] parameters)&#xD;

Edit 2

I had this error

01-22 12:28:06.830: W/System.err(2496): java.lang.IllegalStateException: Content has been consumed

I googled it and I saw that page : Using HttpClient and HttpPost in Android with post parameters

I modified the code and add httpPost.setHeader(“Accept”, “application/json”);

and then magic it entered in the asp .net method but there is a drawback (Although the IllegalStateException stay but it is less important)

It only enter in the method when the method is :

public void SendInterventions(object user)

and not :

public void SendInterventions(String user)

and I can do nothing with that object (can’t be casted to String for example) and if I rename the user parameter it won’t work either. (so we can admit that the json query is parsed because he can detect the user parameter)

I tryied another code :

JSONObject jsonObj = new JSONObject();
jsonObj.put("user", "test");
StringEntity entity = new StringEntity(jsonObj.toString(), HTTP.UTF_8);
entity.setContentType("application/json");
post.setEntity(entity);

same effect .. 🙁 any idea ?

Edit 3

Well I found another very interesting page on WCF REST POST of JSON: Parameter is empty

IF I modify the WebInvoke like :

[WebInvoke(
  RequestFormat = WebMessageFormat.Json,
  BodyStyle = WebMessageBodyStyle.WrappedRequest,
  UriTemplate = "interventions")]

(The BodyStyle parameter was missing, I hope I can send complex json data with that method)

  • 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-28T08:24:33+00:00Added an answer on May 28, 2026 at 8:24 am

    My french is not that good, but I’m guessing that you have to explicitly set the Content-type of your request. The webservice accepts json but the incoming request is raw.

    Try adding application/json as the content-type in your request. Something like this:

    post.setHeader("Content-Type", "application/json");
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Can anybody tell my why this doesn't work in the Android emulator? From the
I am developing a library for Android applications which does not use native code
I am trying to build a web app for Android device using Senahc Touch
I am using the startActivityForResult to get a picture from the android gallery, however
If an application have to support starting from android 1.6 device and onwards. The
I have an Android application which handles a particular type of file. It registers
Trying to work with Eclipse for Android (ADT plugin) development at my iMac (2.4Ghz,
I have a couple of appwidgets released on the Android market and they work
I want to develop an Android application which can run on all ,screen type
Problem Description: We have a service which has applications for main mobile OS’s. We

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.