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

  • Home
  • SEARCH
  • 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 4625586
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T03:17:39+00:00 2026-05-22T03:17:39+00:00

I have a self-hosted WCF web service running, and an Android client application. I

  • 0

I have a self-hosted WCF web service running, and an Android client application. I am able to GET or retrieve data from the web service in json format, however I am unable to POST or send any data to the server.

Below is the code from the WCF service:

 [OperationContract]
 [WebInvoke(Method = "POST",
 UriTemplate = "/SetValue",
 RequestFormat = WebMessageFormat.Json,
 ResponseFormat = WebMessageFormat.Json,
 BodyStyle = WebMessageBodyStyle.Wrapped)]
 public string SetValue(TestClass someValue)
 {
     return someValue.Something.ToString();
 }

[DataContract]
public class TestClass
{
    [DataMember(Name = "something")]
    public int Something
    {
        get;
        set;
    }
}

Below is the code from the Android client:

 HttpClient httpClient = new DefaultHttpClient();
 HttpPost request = new HttpPost("http://xxx.xxx.x.x:8000/SetValue");
 List<NameValuePair> params = new ArrayList<NameValuePair>(1);
 params.add(new BasicNameValuePair("something", "12345"));
 request.setEntity(new UrlEncodedFormEntity(params));
 HttpResponse response = httpClient.execute(request);

The following is how I start the self-hosted service:

 class Program
 {
    static void Main()
    {
        Uri baseAddress = new Uri("http://localhost:8000/");

        using (WebServiceHost host = new WebServiceHost(typeof(ServerSideProfileService), baseAddress))
        {
            host.AddServiceEndpoint(typeof(ServerSideProfileService), new BasicHttpBinding(), "Soap");
            ServiceEndpoint endpoint = host.AddServiceEndpoint(typeof(ServerSideProfileService), new WebHttpBinding(), "Web");
            endpoint.Behaviors.Add(new WebHttpBehavior());

            // Open the service host, service is now listening
            host.Open();
        }
     }
  }

I only have an app.config which just has:

 <?xml version="1.0"?>
 <configuration>
 <startup><supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0"/></startup></configuration>

The response I’m getting when I run httpClient.execute(request) from the Android client includes:

 HTTP/1.1 400 Bad Request
 Request Error
 The server encountered an error processing the request. See server logs for more details.

And that’s pretty much it. I am very new to WCF and don’t know where this ‘server log’ would be, and am at a loss as to how to troubleshoot or debug this? (I have tried Fiddler2 but it doesn’t seem to detect anything from the Android client.)

[EDIT]

I have also tried

 JSONObject json = new JSONObject(); 
 json.put("something", "12345"); 
 StringEntity entity = new StringEntity(json.toString()); 
 entity.setContentEncoding(new BasicHeader(HTTP.CONTENT_TYPE, "application/json"));
 entity.setContentType( new BasicHeader(HTTP.CONTENT_TYPE, "application/json"));  
 request.setEntity(entity); 

which also results in the error.

I also noticed that if I change ‘SetValue’ to return a constant, such as “abcd”, instead of someValue.Something.ToString(), then everything works?

  • 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-22T03:17:40+00:00Added an answer on May 22, 2026 at 3:17 am

    Your client code is sending a html form post formatted payload, but your server is expecting a json payload, you need the client to be something like

    HttpClient httpClient = new DefaultHttpClient();
    HttpPost request = new HttpPost("http://xxx.xxx.x.x:8000/SetValue");
    StringEntity e = new StringEntity("{ \"something\":12345 }", "UTF-8");
    request.setEntity(e);
    request.setHeader("content-type", "application/json");
    HttpResponse response = httpClient.execute(request);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a self-hosted WCF service that is hosted by a desktop application. I
I have a WCF self-hosted service in a Windows Forms application. I am going
I have a self-hosted WCF (as a Windows service), it has a web.config file.
When sending messages from a self hosted WCF service to many clients (about 10
I'm just getting into WCF programming. I've set up a self-hosted test web service
I have a self-hosted WCF REST application which is designed to accept and return
I have a self-hosted WCF REST service based on the WebHttpBinding. One of the
I want to reuse some code logic from a self-hosted web application in my
I have been doing a lot of work with WCF self hosted applications. I
When I create a self hosted wcf application, I create ServiceHost objects for each

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.