Velocity Reviews - Computer Hardware Reviews

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

Reply
Thread Tools

Ajax.net 3.5 JSON and WCF Serialization

 
 
Stilgar[bbs.iscabbs.com]
Guest
Posts: n/a
 
      02-12-2010
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
unreadable):

// The custom object

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

[DataMember]
public string Email { get; set; }

[DataMember]
public string UserName { get; set; }

// Ctor and IComparible stuff omitted
}
}

// The WCF Service .svc.cs code

namespace my.namespacehere
{
[ServiceContract( Namespace = "AdminServices" )]
[AspNetCompatibilityRequirements( RequirementsMode =
AspNetCompatibilityRequirementsMode.Allowed)]
public class LookupServices
{
[OperationContract]
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 )
{
try
{
var parsed =
Sys.Serialization.JavaScriptSerializer.deserialize ( result );
}
catch (e)
{
// I _ALWAYS_ hit this with error:
// Cannot convertSys.ArgumentTypeException:
Sys.ArgumentTypeException:
// Object of type 'Object' cannot be converted to type
'String'. Parameter name: data
alert("exception! " + e);
return;
}
// If I got this far, I'd expect parsed.AccountGuid,
parsed.UserName and parsed.Email
// to contain my data
}
</script>


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

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

What am I overlooking?
 
Reply With Quote
 
 
 
Reply

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 json.org Tuğrul Topuz ASP General 1 06-27-2008 11:37 PM



Advertisments