With either WCF or ASMX, make sure you are adding your services to your pages by using the asp:ScriptManager tag. It will build JavaScript proxies for you, and the advantage is that you don't have to build any parsing at all, regardless of the underlying protocol. It's very, very nice. This example is ASMX, but it's every bit as clean as using WCF.
<asp:ScriptManager ID="ScriptManager1" runat="server">
<Services>
<asp:ServiceReference Path="~/WebServices/Admin/HospitalLocationService.asmx" InlineScript="true" />
</Services>
</asp:ScriptManager>
Also, you can make ASMX send JSON by adding the ScriptService and ScriptMethod attributes:
<System.Web.Services.WebService(Namespace:="http://www.fujimed.com/")> _
<System.Web.Services.WebServiceBinding(ConformsTo:=WsiProfiles.BasicProfile1_1)> _
<ToolboxItem(False)> _
<ScriptService()> _
Public Class HospitalLocationService
Inherits System.Web.Services.WebService
<WebMethod()> _
<ScriptMethod()> _
Public Function GetAll() As List(Of HospitalLocationEntity)
Return (New HospitalLocation()).GetAll().Data
End Function
<WebMethod()> _
<ScriptMethod()> _
Public Function GetByID(ByVal ID As Integer) As HospitalLocationEntity
Return (New HospitalLocation()).GetHospitalLocation(ID).Data
End Function
End Class
Consuming the service, without parsing (this is what the ScriptManager does for you):
function editLocation(id) {
vRIS.HospitalLocationService.GetByID(id, getComplete, getError);
}
function getComplete(results, context, methodName) {
document.all['txtLocation'].value = results.Location;
document.all['txtInterfaceID'].value = results.InterfaceID;
document.all['selActive'].value = results.Active ? "true" : "false";
document.all['hdnLocationID'].value = results.ID.toString();
}
function getError(errorInfo, context, methodName) {
Alert(methodName + " : " + errorInfo);
document.all['txtLocation'].value = "";
document.all['txtInterfaceID'].value = "";
document.all['selActive'].value = "false";
document.all['hdnLocationID'].value = "";
}
Edited to add: With all the above based on ASMX, I'd still go WCF, for versatility and for the ability to define data contracts. Also, investigate WCF RIA Services; they are targeting support for AJAX as well as Silverlight, and it automates much of the configuration of WCF.