Ajax.net 3.5 JSON and WCF Serialization

Discussion in 'ASP .Net Web Services' started by Stilgar[bbs.iscabbs.com], Feb 12, 2010.

  1. I'm trying some WCF ajax.net 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:


    What am I overlooking?
    Stilgar[bbs.iscabbs.com], Feb 12, 2010
    1. Advertisements

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.