Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > ASP .Net Web Services > 3.5 JSON and WCF Serialization

Thread Tools 3.5 JSON and WCF Serialization

Posts: n/a
I'm trying some WCF 3.5 out for the first time, and I'm
having some difficulties. I have a WCF Service which I have connected
to in my aspx page using <asp:ScriptManager>. I have a custom object
which has been decorated as a [DataContract]. I'm calling the object
from javascript successfully, I can see the JSON response in FireBug,
but Sys.Serialization.JavaScriptSerializer.deserialize () chokes on
it. I'm sure I'm making a noob mistake, but I used up all my patience
getting the Web.Config values right for running the WCF service

Here's a mockup of what I'm doing (hopefully wrapping wont make it

// The custom object

namespace my.namespacehere
public class UserAccountData : IComparible
public Guid AccountGuid { get; set; }

public string Email { get; set; }

public string UserName { get; set; }

// Ctor and IComparible stuff omitted

// The WCF Service .svc.cs code

namespace my.namespacehere
[ServiceContract( Namespace = "AdminServices" )]
[AspNetCompatibilityRequirements( RequirementsMode =
public class LookupServices
public UserAccountData GetUserAccountData( Guid accountGuid )
// The code for the static lookup isn't included, but you
get the jist of it
return UserAccount.GetUserAccountData( accountGuid );

// Okay, here's the javascript code in the .aspx

<script type="text/javascript" language="javascript">
function getIt( userGuidReadFromInput )

AdminServices.LookupServices.GetUserAccountData( userGuidReadFromInput,

onSuccess, onFailure, null);

function onSuccess( result )
var parsed =
Sys.Serialization.JavaScriptSerializer.deserialize ( result );
catch (e)
// I _ALWAYS_ hit this with error:
// Cannot convertSys.ArgumentTypeException:
// Object of type 'Object' cannot be converted to type
'String'. Parameter name: data
alert("exception! " + e);
// If I got this far, I'd expect parsed.AccountGuid,
parsed.UserName and parsed.Email
// to contain my data

I can see the JSON being returned from the .svc in Firebug and it
looks like this:

{"__type":"UserAccountData:#my.namespacehere","Acc ountGuid":"ebba480e-8b85-4277-
f57f144af0a9","Email":"(E-Mail Removed)","UserName":" LeeroyJenkins"}}

What am I overlooking?
Reply With Quote

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
I am facing an issue while decoding json string using json.loads sajuptpm Python 2 12-28-2012 07:16 AM
Difference between Ajax Enabled WCF service and regular WCF? Cindy Lee ASP .Net 1 03-19-2010 05:59 PM
AJAX enabled WCF Service Vs Standard WCF Service Simon ASP .Net 0 10-13-2009 09:13 AM
[ANN] Security Fix json-1.1.7 for json_pure and json gems Florian Frank Ruby 0 06-30-2009 05:18 PM
"JSON for ASP" at Tuğrul Topuz ASP General 1 06-27-2008 11:37 PM