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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T15:04:21+00:00 2026-06-06T15:04:21+00:00

I’m trying to build a Rest JSON service with the WCF REST Service Template

  • 0

I’m trying to build a Rest JSON service with the WCF REST Service Template 40 and Entity FrameWork.

When I try to create regular object and return it everything works fine and I get back JSON response (GetEvent Method)

When I try to return object that called from entity framework in XML format everything works fine (GetEvent3 Method)

But When i try to return Json response from object that was called from entity framework I get empty response (GetEvent2 Method)

Any idea why?

This is my code:

    [DataContract]
public class Event
{
    [DataMember]
    public int ID { get; set; }

    [DataType(DataType.Text)]
    [Display(Name = "Event Name")]
    [DataMember]
    public string Name { get; set; }

    [Display(Name = "Event StartTime")]
    [DataMember]
    public DateTime StartTime;

    [Display(Name = "Event EndTime")]
    [DataMember]
    public DateTime EndTime;
}




[ServiceContract]
public interface IService1
{
    [OperationContract]
    [WebGet(UriTemplate = "/GetEvent", ResponseFormat = WebMessageFormat.Json)]
    Event GetEvent();

    [WebGet(UriTemplate = "/GetEvent2", ResponseFormat = WebMessageFormat.Json)]
    Event GetEvent2();

    [WebGet(UriTemplate = "/GetEvent3", ResponseFormat = WebMessageFormat.Xml)]
    Event GetEvent3();
}



[AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)]
[ServiceBehavior(InstanceContextMode = InstanceContextMode.PerCall)]
public class Service1 : IService1
{
    private readonly EventsDB _db = new EventsDB();

    // This method return good response in Json format
    [WebGet(UriTemplate = "/GetEvent", ResponseFormat = WebMessageFormat.Json)]
    public Event GetEvent()
    {
        return new Event
        {
            ID = 1,
            Name = "A vs. B",
            StartTime = new DateTime(2012, 4, 10, 18, 00, 00),
            EndTime = new DateTime(2012, 4, 11, 18, 00, 00),
        };
    }

    // This method return no response
    [WebGet(UriTemplate = "/GetEvent2", ResponseFormat = WebMessageFormat.Json)]
    public Event GetEvent2()
    {
        Event e = _db.Events.ToList()[0];
        return e;
    }

    // This method return good response in XML format
    [WebGet(UriTemplate = "/GetEvent3", ResponseFormat = WebMessageFormat.Xml)]
    public Event GetEvent3()
    {
        Event e = _db.Events.ToList()[0];
        return e;
    }
}

Web.Config

    <?xml version="1.0" encoding="utf-8"?>
<configuration>

  <configSections>
    <!-- For more information on Entity Framework configuration, visit http://go.microsoft.com/fwlink/?LinkID=237468 -->
    <section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=4.3.1.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
  </configSections>

  <connectionStrings>
    <add name="EventsDB"
         connectionString="data source=.\SQLEXPRESS;Integrated Security=SSPI;Initial Catalog=EventsDB"
         providerName="System.Data.SqlClient" />
  </connectionStrings>

  <system.web>
    <compilation debug="true" targetFramework="4.0" />
  </system.web>

  <system.webServer>
    <modules runAllManagedModulesForAllRequests="true">
      <add name="UrlRoutingModule" type="System.Web.Routing.UrlRoutingModule, System.Web, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
    </modules>
  </system.webServer>

  <system.serviceModel>
    <serviceHostingEnvironment aspNetCompatibilityEnabled="true" />
    <standardEndpoints>
      <webHttpEndpoint>
        <standardEndpoint name="" helpEnabled="true" automaticFormatSelectionEnabled="false" defaultOutgoingResponseFormat="Json"/>
      </webHttpEndpoint>
    </standardEndpoints>
    <services>
      <service name="WcfRestService3.Service1">
        <endpoint address="http://localhost:50235/service1"
              binding="webHttpBinding"
              contract="WcfRestService3.IService1" />
      </service>
    </services>
  </system.serviceModel>

  <entityFramework>
    <defaultConnectionFactory type="System.Data.Entity.Infrastructure.SqlConnectionFactory, EntityFramework">
      <parameters>
        <parameter value="Data Source=.\SQLEXPRESS; Integrated Security=True; MultipleActiveResultSets=True" />
      </parameters>
    </defaultConnectionFactory>
  </entityFramework>


</configuration>
  • 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-06T15:04:22+00:00Added an answer on June 6, 2026 at 3:04 pm

    Have you considered using asp.net mvc for your rest services? It’s really straightforward, safe and quick. It’s the kind of thing that for sure makes your life better. A service like the one you’re posting here can be complete in around 20 minutes with no more than 10 lines of code. hope it helps.

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

Sidebar

Related Questions

Basically, what I'm trying to create is a page of div tags, each has
I'm trying to create an if statement in PHP that prevents a single post
I am trying to understand how to use SyndicationItem to display feed which is
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I am trying to render a haml file in a javascript response like so:
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
We're building an app, our first using Rails 3, and we're having to build
I'm trying to select an H1 element which is the second-child in its group
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out

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.