Alex Rivera | Logout

WCF REST POST XML - The remote server returned an error: (400) Bad Request

Asked 2009-05-26T17:40:32.093
12

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>
          <a
Edit
Report

1 Answer

12

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>
answered 2009-05-26T18:52:59.110

Your Answer