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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T19:21:53+00:00 2026-05-11T19:21:53+00:00

I have exposed my REST API service using WCF Service Library and started by

  • 0

I have exposed my REST API service using WCF Service Library and started by console application. when I try to consume the service from client ( another console application), I am getting “Bad Request” exception.

please see the code below :-

[ServiceContract(Namespace = "http://www.test.com/Enrollment")]
public interface IEnrollService
{
    [OperationContract]
    [WebInvoke(Method = "POST", UriTemplate = "enroll", 
           RequestFormat = WebMessageFormat.Xml, 
           ResponseFormat = WebMessageFormat.Xml, 
           BodyStyle= WebMessageBodyStyle.Bare)]
    string EnrollData(Enroll enrData);
}

public class EnrollService : IEnrollService
{
    public string EnrollData(Enroll enrData)
    {
        return "Hello, your test data is " + enrData.AccountNumber; 
    }
}

DataContract

[DataContract(Namespace = "http://www.test.com/Enrollment")]
public class Enroll
{

    [DataMember]
    public string ClientId
    {
        get;
        set;
    }

    [DataMember]
    public string AccountNumber
    {
        get; 
        set; 
    }

    [DataMember]
    public string TaxId
    {
        get; 
        set; 
    }

    [DataMember]
    public string TaxType
    {
        get; 
        set; 
    }

    [DataMember]
    public string EmailAddress
    {
        get; 
        set; 
    }

    [DataMember]
    public string Pin
    {
        get; 
        set; 
    }

    [DataMember]
    public string State
    {
        get; 
        set; 
    }

}

app.config settings

<system.serviceModel>
  <services>
    <service name="OEA.REST.EnrollService" behaviorConfiguration="OEABehavior">
      <endpoint address="http://localhost:8010/OEA/Service/EnrollService" 
                binding="webHttpBinding" behaviorConfiguration="webHttp"
                contract="OEA.REST.IEnrollService" />
      <host>
        <baseAddresses>
          <add baseAddress="http://localhost:8010/OEA/Service/EnrollService" />
        </baseAddresses>
      </host>
    </service>
  </services>
  <behaviors>
    <endpointBehaviors>
      <behavior name="webHttp">
        <webHttp/>
      </behavior>
    </endpointBehaviors>
    <serviceBehaviors>
      <behavior name="OEABehavior">
        <serviceMetadata httpGetEnabled="True" />
        <serviceDebug includeExceptionDetailInFaults="True" />
      </behavior>
    </serviceBehaviors>
  </behaviors>
  <serviceHostingEnvironment aspNetCompatibilityEnabled="true" />
</system.serviceModel>

client code:

HttpWebRequest req = null;
HttpWebResponse res = null;
try
{
    string url = "http://localhost:8010/OEA/Service/EnrollService/enroll";
    req = (HttpWebRequest)WebRequest.Create(url);
    req.Method = "POST";
    req.ContentType = "application/xml; charset=utf-8";
    req.Timeout = 30000;
    req.Headers.Add("SOAPAction", url);              

    System.Xml.XmlDocument xmlDoc = new System.Xml.XmlDocument();
    xmlDoc.XmlResolver = null;
    xmlDoc.Load(@"d:\test.xml");
    string sXML = xmlDoc.InnerXml;
    req.ContentLength = sXML.Length;
    System.IO.StreamWriter sw = new System.IO.StreamWriter(req.GetRequestStream());
    sw.Write(sXML);
    sw.Close();

    res = (HttpWebResponse)req.GetResponse();
}
catch (Exception ex)
{
    System.Console.WriteLine(ex.Message);
}

content of test.xml

<Enroll>
    <ClientId>000</ClientId>
    <AccountNumber>123</AccountNumber>
    <TaxId>123</TaxId>
    <TaxType>123</TaxType>
    <EmailAddress>123</EmailAddress>
    <Pin>123</Pin>
    <State>122</State>
</Enroll>

I am getting “Bad Request” exception on req.GetResponse() method call. Just started learning REST. I am stuck up with POST request. Any help would be highly appreciated. Thanks in advance.

  • 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-11T19:21:54+00:00Added an answer on May 11, 2026 at 7:21 pm

    Your POST payload should be :

    <Enroll xmlns="http://www.test.com/Enrollment">
    <ClientId>000</ClientId>
    <AccountNumber>123</AccountNumber>
    <TaxId>123</TaxId>
    <TaxType>123</TaxType>
    <EmailAddress>123</EmailAddress>
    <Pin>123</Pin>
    <State>122</State>
    </Enroll>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 258k
  • Answers 258k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Information about this topic really is rare (but that's nothing… May 13, 2026 at 11:00 am
  • Editorial Team
    Editorial Team added an answer You can convert ReST to DocBook using pandoc. May 13, 2026 at 11:00 am
  • Editorial Team
    Editorial Team added an answer It's not exactly Python, but there's a pretty standard *nix… May 13, 2026 at 11:00 am

Related Questions

I am planning on putting up a web service, or some other service exposed
I'm building a REST API that exposes data as XML. I've got a whole
I'm writing a small application which exposes a simple REST-ish HTTP API. I'm stuck
I'm interested in exposing a direct REST interface to collections of JSON documents (think

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.