WCF controlling JSON output
-
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
-
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
-
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
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."
-
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
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."
-
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."
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