Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. WCF and WF
  4. WCF controlling JSON output

WCF controlling JSON output

Scheduled Pinned Locked Moved WCF and WF
csharpphpasp-netdatabasewcf
5 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    Mark J Miller
    wrote on last edited by
    #1

    I have a WCF service hosted in an ASP.NET application (.svc item). I have an operation contract which returns IList where T is a custom object. Here's the contract definition: [OperationContract] [WebInvoke(BodyStyle = WebMessageBodyStyle.Wrapped, RequestFormat = WebMessageFormat.Json, ResponseFormat = WebMessageFormat.Json, UriTemplate = "/FindTeamsByZipCode")] IList<TeamEx> FindTeamsByZipCode(Guid ssid, String zipCode, Double radius); The output of the operation looks something like this: {"FindTeamsByZipCode":[{"id":1,"name":"team"},{"id":2,"name":"team2"}]} Is there any way I can control the value of the "root" (ie. {"FindTeamsByZipCode":)?

    Code responsibly: OWASP.org Mark's blog: developMENTALmadness.blogspot.com

    M M 2 Replies Last reply
    0
    • M Mark J Miller

      I have a WCF service hosted in an ASP.NET application (.svc item). I have an operation contract which returns IList where T is a custom object. Here's the contract definition: [OperationContract] [WebInvoke(BodyStyle = WebMessageBodyStyle.Wrapped, RequestFormat = WebMessageFormat.Json, ResponseFormat = WebMessageFormat.Json, UriTemplate = "/FindTeamsByZipCode")] IList<TeamEx> FindTeamsByZipCode(Guid ssid, String zipCode, Double radius); The output of the operation looks something like this: {"FindTeamsByZipCode":[{"id":1,"name":"team"},{"id":2,"name":"team2"}]} Is there any way I can control the value of the "root" (ie. {"FindTeamsByZipCode":)?

      Code responsibly: OWASP.org Mark's blog: developMENTALmadness.blogspot.com

      M Offline
      M Offline
      manfbraun
      wrote on last edited by
      #2

      Hi ! Sorry, that I do NOT have the answer. Allow me a question so:How do you get it serialized this way???? That's what I wish, but never got! I use the same contract definition like you use.

      Ciao, mb

      M 1 Reply Last reply
      0
      • M manfbraun

        Hi ! Sorry, that I do NOT have the answer. Allow me a question so:How do you get it serialized this way???? That's what I wish, but never got! I use the same contract definition like you use.

        Ciao, mb

        M Offline
        M Offline
        Mark J Miller
        wrote on last edited by
        #3

        You need the correct service config: <system.serviceModel> <behaviors> <endpointBehaviors> <behavior name="jsonBehavior"> <webHttp/> </behavior> </endpointBehaviors> <serviceBehaviors> <behavior name="MvcApplication.Services.TeamBehavior"> <serviceMetadata httpGetEnabled="true"/> <serviceDebug includeExceptionDetailInFaults="true"/> </behavior> </serviceBehaviors> </behaviors> <services> <service behaviorConfiguration="MvcApplication.Services.TeamBehavior" name="MvcApplication.Services.Team"> <endpoint behaviorConfiguration="jsonBehavior" address="" binding="webHttpBinding" contract="MvcApplication.Services.ITeam"> <identity> <dns value="www.mydomain.com"/> </identity> </endpoint> <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"/> </service> </services> </system.serviceModel> what this does is define an endpointBehvior which turns on webHttp and a serviceBehavior which enables httpGet. Then apply the serviceBehaior to your service element and the endpointBehavior to your endpoint config.

        Code responsibly: OWASP.org Mark's blog: developMENTALmadness.blogspot.com Click here for Free Industry White Papers/Magazines! Bill Cosby - "A word to the wise ain't necessary - it's the stupid ones that need the advice."

        1 Reply Last reply
        0
        • M Mark J Miller

          I have a WCF service hosted in an ASP.NET application (.svc item). I have an operation contract which returns IList where T is a custom object. Here's the contract definition: [OperationContract] [WebInvoke(BodyStyle = WebMessageBodyStyle.Wrapped, RequestFormat = WebMessageFormat.Json, ResponseFormat = WebMessageFormat.Json, UriTemplate = "/FindTeamsByZipCode")] IList<TeamEx> FindTeamsByZipCode(Guid ssid, String zipCode, Double radius); The output of the operation looks something like this: {"FindTeamsByZipCode":[{"id":1,"name":"team"},{"id":2,"name":"team2"}]} Is there any way I can control the value of the "root" (ie. {"FindTeamsByZipCode":)?

          Code responsibly: OWASP.org Mark's blog: developMENTALmadness.blogspot.com

          M Offline
          M Offline
          Mark J Miller
          wrote on last edited by
          #4

          Someone replied to this on my blog, so here's the answer to this question: http://developmentalmadness.blogspot.com/2008/07/using-extjs-with-wcf.html?showComment=1233623820000#c2548991491818677062[^]

          Code responsibly: OWASP.org Mark's blog: developMENTALmadness.blogspot.com Click here for Free Industry White Papers/Magazines! Bill Cosby - "A word to the wise ain't necessary - it's the stupid ones that need the advice."

          M 1 Reply Last reply
          0
          • M Mark J Miller

            Someone replied to this on my blog, so here's the answer to this question: http://developmentalmadness.blogspot.com/2008/07/using-extjs-with-wcf.html?showComment=1233623820000#c2548991491818677062[^]

            Code responsibly: OWASP.org Mark's blog: developMENTALmadness.blogspot.com Click here for Free Industry White Papers/Magazines! Bill Cosby - "A word to the wise ain't necessary - it's the stupid ones that need the advice."

            M Offline
            M Offline
            manfbraun
            wrote on last edited by
            #5

            Hi Mark! Thanks for the pointer! That's really good. In the meantime, I also found other good hints and finally, I maestred the [your] app. The most time, I've spent time with, was your typo on the exjs grid ["colums" instead of "columns"] ;-) [I was not able to read this :-( ]. Many thanks for the tipps and the demo!!

            Ciao, mb

            1 Reply Last reply
            0
            Reply
            • Reply as topic
            Log in to reply
            • Oldest to Newest
            • Newest to Oldest
            • Most Votes


            • Login

            • Don't have an account? Register

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • World
            • Users
            • Groups