Table of Contents

IT:AD:ASP.NET:Win Forms:AJAX

Attributes

Attributes:ASP.NET

There are a couple of Attributes used to make methods accessible from script:

Attributes:WebServices

Personally, I don't do WebServices. Period. Pre-SOAP protocol that is depracated.. Use WCF and WebAPI, with WebHttpBehavior, etc.

Attributes:WCF

Examples:

    [ServiceContract]
    public interface ICalculator
    {
      [OperationContract]
      [WebGet(UriTemplate = "Mult?x={x}&y={y}", BodyStyle = WebMessageBodyStyle.Bare)]
      long Multiply(long x, long y);

      [OperationContract]
      [WebGet(UriTemplate = "Div?x={x}&y={y}", RequestFormat = WebMessageFormat.Xml)]
      long Divide(long x, long y);

      [OperationContract]
      [WebGet(ResponseFormat= WebMessageFormat.Json)]
      long Mod(long x, long y);
    }
    

Example:


    [ServiceContract]
    public interface ICalculator2
    {
      [OperationContract]
      [WebInvoke]
      long Add(long x, long y);

      [OperationContract]
      [WebInvoke(UriTemplate = "Sub?x={x}&y={y}")]
      long Subtract(long x, long y);

      [OperationContract]
      [WebInvoke(UriTemplate = "Mult?x={x}&y={y}", BodyStyle = WebMessageBodyStyle.Bare)]
      long Multiply(long x, long y);

      [OperationContract]
      [WebInvoke(UriTemplate = "Div?x={x}&y={y}", BodyStyle = WebMessageBodyStyle.Bare, RequestFormat = WebMessageFormat.Xml, ResponseFormat=WebMessageFormat.Xml)]
      long Divide(long x, long y);

      [OperationContract]
      [WebInvoke(Method = "POST", UriTemplate = "Mod?x={x}&y={y}")]
      long Mod(long x, long y);
    }

RAW

http://andre-pedroso.blogspot.co.nz/2011/02/post-json-to-mvc-controller-with.html

Resources