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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T20:41:19+00:00 2026-05-18T20:41:19+00:00

I’m asking this question after searching the web for an answer for 2 days.

  • 0

I’m asking this question after searching the web for an answer for 2 days.

OK, here’s the thing :

In the server side i have a WCF webservice, defined like this:

namespace HelloRest
{
[System.ServiceModel.ServiceContract]
public interface IHelloRest
  {
    [OperationContract]
    [WebInvoke(
        Method = "POST",
        UriTemplate = "SaveVehicle",
        BodyStyle = WebMessageBodyStyle.WrappedRequest,
        ResponseFormat = WebMessageFormat.Json,
        RequestFormat = WebMessageFormat.Json)]
    string SaveVehicle(clVehicles vehicles);
  }
}

namespace HelloRest
{
  public class HelloRestService : IHelloRest
{
   public string SaveVehicle(clVehicles vehicles)
    {
    ...
    }
}
}


namespace WebApplication1
{

    [Serializable]
    [DataContract]
    public class clVehicles
    {
        [DataMember]
        public List<Vehicle> Vehicles { get; set; }
    }
}


namespace WebApplication1
{

    [Serializable]
    [DataContract]
    public class Vehicle
    {

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

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

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

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

And Im trying to consume this webservice with Android, this way:

HttpPost request = new HttpPost(Consts.URL + "/SaveVehicle");
request.setHeader("Accept", "application/json");
request.setHeader("Content-type", "application/json");

JSONStringer v = new JSONStringer();
v.object();
v.key("Vehicles");
v.object();
v.key("plate").value(plate);
v.key("make").value(make);
v.key("model").value(model);
v.key("year").value(Integer.parseInt(year.toString()));
v.endObject();
v.endObject();
JSONArray arr = new JSONArray();
arr.put(v);

JSONStringer vehicle = new JSONStringer();
vehicle.object();
vehicle.key("vehicles").value(arr);
vehicle.endObject();

StringEntity entity = new StringEntity(vehicle.toString());
request.setEntity(entity);
// Send request to WCF service
DefaultHttpClient httpClient = new DefaultHttpClient();
HttpResponse response = httpClient.execute(request);

The problem :

When I’m launching the client, the request is forwarded to the server (I have a breakpoint inside the “SaveVehicle” function) properly.

The problem is with the function’s parameter : “vehicles” – this object (suppose to) contains only one member – “Vehicles”, which is of type : List.
No matter what I’m sending from the client side, I’m getting null value for this inner container (“Vehicles”).

I’ve tried almost everything! I’m sure the problem is somewhere in the JSONStringer area…

  • 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-18T20:41:20+00:00Added an answer on May 18, 2026 at 8:41 pm

    Found an answer:
    Define your classes as follow:

    namespace WebApplication1
    {
     [KnownType(typeof(Vehicle))]
     [DataContract]
     public class Vehicle
     {
     }
    }
    
    
    namespace WebApplication1
    {
     [CollectionDataContract]
     [KnownType(typeof(Vehicle))]
     public class clVehicles: List<Vehicle>
     {      
     }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

No related questions found

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.