Re: ScriptMethod Attribute... ResponseFormat.Json - Is it Necessary?

Discussion in 'ASP .Net' started by Cowboy \(Gregory A. Beamer\), Jan 27, 2009.

  1. If the service is used for other types of clients (SOA implementation), I
    would not choose JSON as my first alternative. I am not saying you cannot
    use JSON in a SOA implementation, but the benefits of SOAP (having a schema)
    outweigh the slightly lower overhead of JSON.

    If this is AJAX, or a service that will never be consumed by any outside
    entity, then JSON does reduce a bit of the weight and is applicable. For
    AJAX, JSON is becomming the standard, unless the tide turns.

    --
    Gregory A. Beamer
    MVP; MCP: +I, Se, SD, DBA

    Blog:
    http://feeds.feedburner.com/GregoryBeamer

    *************************************************
    | Think outside the box! |
    *************************************************
    "Jordan S" <> wrote in message
    news:OQ%...
    > In the method below, you can see two attributes, the first WebMethod, and
    > the second sets the response format explicitly to JSON.
    >
    > My question: Is the 2nd attribute somehow important [to include, as below]
    > even when the string return value from the method *is* a JSON-formatted
    > string (i.e., not XML)?
    >
    > [System.Web.Services.WebMethod]
    > [System.Web.Script.Services.ScriptMethod(ResponseFormat =
    > ResponseFormat.Json)]
    > public static string GetSomeData(object valueIn1, string valueIn2)
    > {
    > ...
    > return theString; // is a JSON-formatted string
    > }
    >
    > I have tested it both ways (including and excluding that 2nd attribute),
    > and it worked (meaning the client received the result as JSON). But "it
    > works" isn't necessarily the standard I'm shooting for. I'd like to know
    > if it's a good idea or in some cases required even when the return value
    > is a JSON string.
    >
    > Thanks.
    >
    Cowboy \(Gregory A. Beamer\), Jan 27, 2009
    #1
    1. Advertising

  2. Personally? I would leave the attribute, as it clearely informs others of
    your intent and guarantees the runtime will deliver JSON.

    --
    Gregory A. Beamer
    MVP; MCP: +I, Se, SD, DBA

    Blog:
    http://feeds.feedburner.com/GregoryBeamer

    *************************************************
    | Think outside the box! |
    *************************************************
    "Jordan S" <> wrote in message
    news:%...
    > <snip>
    >
    >> If the service is used for other types of clients (SOA implementation), I
    >> would not choose JSON as my first alternative. I am not saying you cannot
    >> use JSON in a SOA implementation, but the benefits of SOAP (having a
    >> schema) outweigh the slightly lower overhead of JSON.
    >>
    >> If this is AJAX, or a service that will never be consumed by any outside
    >> entity, then JSON does reduce a bit of the weight and is applicable. For
    >> AJAX, JSON is becomming the standard, unless the tide turns.

    >
    > Thanks for the feedback. FWIW, this is an AJAX implementation, and the
    > server-side methods in question aren't part of a SOA endpoint and are
    > intended only for use by the current app.
    >
    > Having stated that, what about the question in the OP- is it safe or
    > reasonable to omit that second attribute?
    >
    > Thanks!
    >
    Cowboy \(Gregory A. Beamer\), Jan 27, 2009
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Florian Frank
    Replies:
    0
    Views:
    222
    Florian Frank
    Jun 30, 2009
  2. sajuptpm
    Replies:
    2
    Views:
    311
    sajuptpm
    Dec 28, 2012
  3. Acácio Centeno
    Replies:
    1
    Views:
    238
    dieter
    Feb 15, 2013
  4. Bryan Britten
    Replies:
    9
    Views:
    253
    Bryan Britten
    May 28, 2013
  5. David Karr
    Replies:
    1
    Views:
    150
    David Karr
    Jun 17, 2013
Loading...

Share This Page