Showing posts with label LINQ. Show all posts
Showing posts with label LINQ. Show all posts

Wednesday, October 12, 2011

WCF SOAP REST WsHttpBinding webHttpBinding


BasicHttpBinding vs wsHttpBinding vs WebHttpBinding





  • webHttpBinding is the REST-style binding, where you basically just hit a URL and get back a truckload of XML or JSON from the web service
  • basicHttpBinding and wsHttpBinding are two SOAP-based bindings which is quite different from REST. SOAP has the advantage of having WSDL and XSD to describe the service, its methods, and the data being passed around in great detail (REST doesn't have anything like that - yet). On the other hand, you can't just browse to a wsHttpBinding endpoint with your browser and look at XML - you have to use a SOAP client, e.g. the WcfTestClient or your own app
So your first decision must be: REST vs. SOAP (or you can expose both types of endpoints from your service - that's possible, too).
Then, between basicHttpBinding and wsHttpBinding, there differences are as follows:

Tuesday, October 11, 2011

Drop the Soap : WCF , REST , .NET4 , LINQ


Drop the Soap: WCF, REST, URIs in .NET 4


This post will cover REST in .NET 4 and Visual Web Developer 2010.

Getting Started

To get started we’ll create a basic WCF Rest Service Application
using the new on-line templates option in VVD 2010:



Dude Where’s my .Svc File?

The WCF REST template shows us the new way we can simply build services.  Before we talk about what’s there, let’s look at what is not there:
  • The .Svc File
  • An Interface Contract
  • Dozens of lines of configuration that you have to change to make your service work
REST in .NET 4 is greatly simplified and leverages the Web Routing capabilities used in ASP.NET MVC and other parts of the web frameworks.  With REST in .NET 4 you use a global.asax to set the route to your service using the new ServiceRoute class.  From there, the WCF runtime handles dispatching service calls to the methods based on the Uri Templates.






~ ~ ~ 
wcf 4 linq  :



WCF and LINQ to SQL


WCF and LINQ to SQL (Part 2 (Creates))


WCF and LINQ to SQL (Part 3 (Deletes))


WCF and LINQ to SQL (Part 4 – Updates)






Simple 5 steps to expose WCF services using REST style

http://bitcast-g.bitgravity.com/iplayerhd/data/1/55936c11.mp4





The advantages of using JSON enabled WCF service is that the data is communicated in plain text like stream, it does not require any data/message parsing. For exposing a WCF service as JSON enabled WCF service, we need to apply the [WebGet] attribute on the method of the ServiceContract with ResponseFormat as JSON. The binding used here is WebHttpBinding which is also used for REST enable WCF services. While exposing WCF as JSON enable service, the EndPointBehavior for the WCF service is WebHttp which generates JSON response from the WCF service.


IService1.cs : 



using System.Collections.Generic;
using System.Runtime.Serialization;
using System.ServiceModel;
using System.ServiceModel.Web;


namespace WCF_JSONService
{
    [ServiceContract]
    public interface IService1
    {
        [OperationContract]
        // [WebGet(UriTemplate = "/Products",ResponseFormat=WebMessageFormat.Json)]
        [WebGet(UriTemplate = "/Products", ResponseFormat = WebMessageFormat.Xml)]
        List GetAllProducts(); 
    }




    [DataContract]
    public class Product
    {
        [DataMember]
        public int ProdId { get; set; }
        [DataMember]
        public string PropName { get; set; }
        [DataMember]
        public int Quantity { get; set; }
        [DataMember]
        public int Price { get; set; }
    }
}


Service1.svc : 

using System.Collections.Generic;

namespace WCF_JSONService
{
    public class Service1 : IService1
    {
        public List GetAllProducts()
        {
            return new List
            {
                 new Product() {ProdId=101,PropName="Laptop",Quantity=200,Price=45000},
                 new Product() {ProdId=102,PropName="Desktop",Quantity=300,Price=35000},
            };
        }
    }
}