user1108948
user1108948

Reputation:

WCF Rest coed for Json

Usually I see the code of WCF REST JSON is likely:

// Start the service and browse to <a href="http://:/SampleService/help[ServiceContract]  public">http://<machine_name>:<port>/SampleService/help [ServiceContract]
 public interface ISampleService {
[WebGet(UriTemplate = "")]
List<SampleItem> GetCollection();

That means interface is introduced. But in some occurence I saw in the code interface is never used at all. Such as

 [ServiceContract(Namespace = "")]
[AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)]
public class AlertService
{
    AlertContext alertProxy = new AlertContext();
    AlertDetailsContext alertDetailProxy = new AlertDetailsContext();
    Analytics analyticsProxy = new Analytics();

    [OperationContract]
    [WebInvoke(BodyStyle=WebMessageBodyStyle.Bare, RequestFormat=WebMessageFormat.Json, ResponseFormat=WebMessageFormat.Json, UriTemplate="/SearchAlerts")]
    public List<Alert> SearchAlerts(AlertFilter filter)
    {
        WebOperationContext.Current.OutgoingResponse.Headers.Add("Cache-Control", "no-cache, must-revalidate");
        WebOperationContext.Current.OutgoingResponse.Headers.Add("Expires", "Sat, 26 Jul 1997 05:00:00 GMT");

Here class is used directly, why?

Upvotes: 0

Views: 105

Answers (1)

jrummell
jrummell

Reputation: 43087

Because the ServiceContract doesn't have to be an interface contract. Using an interface allows you to share the same contract among multiple implementations and can make unit testing possible, but it is not required.

Upvotes: 1

Related Questions