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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T22:14:28+00:00 2026-06-01T22:14:28+00:00

I’m creating a skeleton algorithm of a restful service showing how to handle post

  • 0

I’m creating a skeleton algorithm of a restful service showing how to handle post and get requests. from my example get is working fine, however post does not. i guess i should add stuff to web.config, but i don’t know what and why. thanks in advance, Zoli.

 [ServiceContract]
public interface IRestfulService
{
    [OperationContract]
    [WebGet(UriTemplate = "/GetAStudent")]
    Student GetExistingStudent();

    [OperationContract]
    [WebInvoke(UriTemplate = "/GetTheGivenStudent/{studentName}", Method = "POST")]
    Student GetGivenStudent(string studentName);
}



public class RestfulService : IRestfulService
{
    public Student GetExistingStudent()
    {
        Student stdObj = new Student
        {
            StudentName = "Foo",
            Age = 29,
            Mark = 95
        };
        return stdObj;
    }

    public Student GetGivenStudent(string studentName)
    {
        Student stdObj = new Student
        {
            StudentName = studentName,
            Age = 29,
            Mark = 95
        };
        return stdObj;
    }
}

 [DataContract]
public class Student
{
    [DataMember]
    public string StudentName { get; set; }
    [DataMember]
    public int Age { get; set; }
    [DataMember]
    public double Mark { get; set; }
} 

web.config:

<system.web>
    <compilation debug="true" targetFramework="4.0" />
</system.web>
<system.serviceModel>
    <protocolMapping>
        <add scheme="http" binding="webHttpBinding"/>
    </protocolMapping>


    <behaviors>
        <serviceBehaviors>
            <behavior>
                <!-- To avoid disclosing metadata information, set the value below to false and remove the metadata endpoint above before deployment -->
                <serviceMetadata httpGetEnabled="true"/>
                <!-- To receive exception details in faults for debugging purposes, set the value below to true.  Set to false before deployment to avoid disclosing exception information -->
                <serviceDebug includeExceptionDetailInFaults="false"/>
            </behavior>

        </serviceBehaviors>
        <endpointBehaviors>
            <behavior>
                <webHttp />
            </behavior >
        </endpointBehaviors>

    </behaviors>


    <serviceHostingEnvironment multipleSiteBindingsEnabled="true" />
</system.serviceModel>
<system.webServer>
    <modules runAllManagedModulesForAllRequests="true"/>
</system.webServer>

  • 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-01T22:14:29+00:00Added an answer on June 1, 2026 at 10:14 pm

    You don’t need to expose the mex endpoint for a REST service. Your web.config should look something like this:

    <?xml version="1.0" encoding="UTF-8"?>
    <configuration>
      <system.web>
        <compilation debug="true" targetFramework="4.0" />
      </system.web>
      <system.serviceModel>
        <serviceHostingEnvironment aspNetCompatibilityEnabled="true" />
        <services>
          <service name="BookService">
    
            <!-- Expose an XML endpoint: -->
            <endpoint name="xml"
                  address="xml"
                  binding="webHttpBinding"
                  contract="BookStore.Contracts.IBookService"
                  behaviorConfiguration="poxBehavior" />
    
            <!-- Expose a JSON endpoint: -->
            <endpoint name="json"
                  address="json"
                  binding="webHttpBinding"
                  contract="BookStore.Contracts.IBookService"
                  behaviorConfiguration="jsonBehavior" />
          </service>
        </services>
        <behaviors>
          <endpointBehaviors>
            <behavior name="poxBehavior">
               <webHttp />
            </behavior>
          <endpointBehaviors>
            <behavior name="jsonBehavior">
               <enableWebScript />
            </behavior>
          </endpointBehaviors>
        </behaviors>
      </system.serviceModel>
    </configuration>
    

    The above would expose two endpoints, one that uses XML data, and one that uses JSON. Exposing two endpoints like this is completely optional of course; it’s just an example of what you could do.

    I also like to use routing for REST services; something like in your Global.asax.cs:

    protected void Application_Start(object sender, EventArgs e)
    {
        RouteTable.Routes.Add(
            new System.ServiceModel.Activation.ServiceRoute("books",
                new System.ServiceModel.Activation.WebServiceHostFactory(),
                typeof(BookStore.Services.BookService)
            )
        );
    }
    

    Which, using the above endpoints in the example web.config, would allow the service to be accessed like this:

    http://yourdomain.com/books/xml
    

    and if you choose to use or add the json endpoint, like this:

    http://yourdomain.com/books/json
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
For some reason, after submitting a string like this Jack’s Spindle from a text
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I have a text area in my form which accepts all possible characters from
Does anyone know how can I replace this 2 symbol below from the string
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
i got an object with contents of html markup in it, for example: string
I am currently running into a problem where an element is coming back from
I am writing an app with both english and french support. The app requests

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.