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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T05:21:53+00:00 2026-06-02T05:21:53+00:00

I am having a real difficult time figuring out why I am getting a

  • 0

I am having a real difficult time figuring out why I am getting a 400 bad request from my POST method on my client side. My other POST methods work fine for this service and client. Yet this one isnt working? I was hoping a fresh pair of eyes might find the problem?

My Service looks like this:

    [OperationContract]
    [WebInvoke(Method = "POST", BodyStyle = WebMessageBodyStyle.Bare, RequestFormat = WebMessageFormat.Xml, ResponseFormat = WebMessageFormat.Xml, UriTemplate = "/Message")]
    void AddMessage(Message message);
    //Post Method for Message

    [DataContract(Name = "Message")]
    public class Message
    {
    [DataMember(Name = "MessageID")]
    public string MessageID { get; set; }
    [DataMember(Name = "GroupMessage")]
    public string GroupMessage { get; set; }
    //DataContracts for Message


    [ServiceBehavior(InstanceContextMode = InstanceContextMode.Single)] 
    public class RawDataService : IReceiveData
    {
    List<Message> messages = new List<Message>();
    int eCount = 0;

    public void AddMessage(Message message)
    {
        message.MessageID = (++eCount).ToString();
        messages.Add(message);
    }
    // add message method, increment MessageID

Client Code to Post which gives the 400 bad request on marked line:

    private void button15_Click(object sender, EventArgs e)
    {
        string uriMessage = "http://localhost:8000/Service/Message";
        StringBuilder sb1 = new StringBuilder();
        sb1.AppendLine("</Message>");
        sb1.AppendLine("<GroupMessage>" + this.textBox22.Text + "</GroupMessage>");
        sb1.AppendLine("</Message>");
        string GroupMessage = sb1.ToString();
        byte[] arr1 = Encoding.UTF8.GetBytes(GroupMessage);
        HttpWebRequest req1 = (HttpWebRequest)WebRequest.Create(uriMessage);
        req1.Method = "POST";
        req1.ContentType = "application/xml";
        req1.ContentLength = arr1.Length;
        Stream reqStrm1 = req1.GetRequestStream();
        reqStrm1.Write(arr1, 0, arr1.Length);
        reqStrm1.Close();
        HttpWebResponse resp1 = (HttpWebResponse)req1.GetResponse(); //400 bad request?
        MessageBox.Show(resp1.StatusDescription);
        reqStrm1.Close();
        resp1.Close();
    }
  • 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-02T05:21:54+00:00Added an answer on June 2, 2026 at 5:21 am

    This might be it.

    sb1.AppendLine("</Message>");
    sb1.AppendLine("<GroupMessage>" + this.textBox22.Text + "</GroupMessage>");
    sb1.AppendLine("</Message>");
    

    The opening Message element is actually a closing element.

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

Sidebar

Related Questions

I'm having a real difficult time getting this code to work. I'm trying to
I'm having a real hard time trying to figure out how to fix this
So I am having some real difficulty figuring out how to make the following
I am having real difficulty getting my head around the issue of setting the
I'm having real problems getting PDO_MYSQL working. I started by just trying to install
First time cake user and I'm having real apache problems. For some reason the
I'm having real trouble getting my head around this issue. As the title suggests,
I'm having real problems getting a ProgressDialog up and running. My code: ProgressDialog dialog;
I'm having a difficult time understanding where actual Leaks are happening and where they
I'm having real difficulty getting access to a variable that is an attribute of

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.