Click here to Skip to main content
15,031,962 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more: , +
Hi,

Hi want to wcf rest service using json response fromat using linq/edm can u guide me or send snippets
My Method like
C#
[OperationContract]
      [WebGet(UriTemplate = "GetBookById/?id={id}", ResponseFormat = WebMessageFormat.Json, BodyStyle = WebMessageBodyStyle.Wrapped)]
      Book GetBookById(string id);



public Book GetBookById(string id)
      {
          try
          {
              int bookId = Convert.ToInt32(id);

              using (SAMPLEDBEntities entities = new SAMPLEDBEntities())
              {
                  return entities.Books.SingleOrDefault(book => book.ID == bookId);
              }
          }
          catch
          {
              throw new FaultException("Something went wrong");
          }
      }

How can i consume whole data using uri i need to get data into list into from service
Posted
Updated 4-Oct-13 0:15am
v2
Comments
Jameel VM 4-Oct-13 5:37am
   
did you try anything?
kingsa 4-Oct-13 5:48am
   
yes

My Method like
[OperationContract]
[WebGet(UriTemplate = "GetBookById/?id={id}", ResponseFormat = WebMessageFormat.Json, BodyStyle = WebMessageBodyStyle.Wrapped)]
Book GetBookById(string id);



public Book GetBookById(string id)
{
try
{
int bookId = Convert.ToInt32(id);

using (SAMPLEDBEntities entities = new SAMPLEDBEntities())
{
return entities.Books.SingleOrDefault(book => book.ID == bookId);
}
}
catch
{
throw new FaultException("Something went wrong");
}
}
How can i consume whole data using uri i need to get data into list into from service
Jameel VM 4-Oct-13 6:21am
   
from where you want to consume the service?
kingsa 4-Oct-13 7:46am
   
from now iis (currently) after that into deploying Was we consume from there

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900