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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T05:05:47+00:00 2026-06-13T05:05:47+00:00

I having a problem with my android client trying to post a JSON class

  • 0

I having a problem with my android client trying to post a JSON class to my wcf service.
Here is the code for android client :

    public HttpResponse TestPost() throws Exception 
{

    HttpPost httpost = new HttpPost(url+"/TestPost");

    JSONStringer img = new JSONStringer()
        .object()
        .key("TestModel")
            .object()
                .key("p1").value("test")
                .key("p2").value("test")
                .key("p3").value(1)
                .key("p4").value("test")
                .key("p5").value(2)
                .key("p6").value("test;test")
            .endObject()
        .endObject();
        StringEntity se = new StringEntity(img.toString());

    httpost.setEntity(se);

    httpost.setHeader("Accept", "application/json");
    httpost.setHeader("Content-type", "application/json");

    return httpclient.execute(httpost);
}

Here is code for Wcf

    [OperationContract]
    [WebInvoke(Method = "POST",
        RequestFormat = WebMessageFormat.Json,
        ResponseFormat = WebMessageFormat.Json,
        BodyStyle = WebMessageBodyStyle.Wrapped,
        UriTemplate = "TestPost")]
    void TestPost(TestModel tm);





[DataContract]
public class TestModel
{
    [DataMember(Name = "p1")]
    public string p1 { get; set; }

    [DataMember(Name = "p2")]
    public string p2{ get; set; }

    [DataMember(Name = "p3")]
    public int p3 { get; set; }

    [DataMember(Name = "p4")]
    public string p4 { get; set; }

    [DataMember(Name = "p5")]
    public int p5 { get; set; }

    [DataMember(Name = "p6")]
    public string p6 { get; set; }

}

In my wcf method the parameter TestModel tm is always null. What could possibly be wrong?

  • 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-06-13T05:05:48+00:00Added an answer on June 13, 2026 at 5:05 am

    The wrapping of the object (since you specified WebMessageBodyStyle.Wrapped) is done based on the parameter name, not the parameter type. The name of the outermost JSON member should be “tm”, not “TestModel”:

    public HttpResponse TestPost() throws Exception  
    { 
        HttpPost httpost = new HttpPost(url+"/TestPost"); 
    
        JSONStringer img = new JSONStringer() 
            .object() 
            .key("tm") 
                .object() 
                    .key("p1").value("test") 
                    .key("p2").value("test") 
                    .key("p3").value(1) 
                    .key("p4").value("test") 
                    .key("p5").value(2) 
                    .key("p6").value("test;test") 
                .endObject() 
            .endObject(); 
            StringEntity se = new StringEntity(img.toString()); 
    
        httpost.setEntity(se); 
    
        httpost.setHeader("Accept", "application/json"); 
        httpost.setHeader("Content-type", "application/json"); 
    
        return httpclient.execute(httpost); 
    } 
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm having a problem with Android layout.. what I'm trying to create is something
I'm newbie to Android development. I'm having problem here and hope someone could help
I am trying to call a web service from Android client on the Magento
On Android, I'm having a problem trying to figure out which ringtone is actually
Well I am having a stranger problem here in my android app. I made
I'm having a problem with android. I'm setting the Weight parameter in Java, but
i am having a small problem with my android application. I have some mp3
I am having a problem with views overlapping in a RelativeLayout on Android 1.5...
Possible Duplicate: Android Launch an application from another application I am having a problem
I'm working on a memory game for Android and I'm having a problem. When

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.