none
Problem going to through BigShelf - RiaServices.Jquery - Metadata is undefined?

    Question

  • I've been going through this page: http://wcf.codeplex.com/wikipage?title=jQueryRia&referringTitle=WCF%20jQuery 

    I finally got data coming back from my Ria Service but the JQuery crashes. Inside of DataContext.js there is a callback function on line 133 that is called when the data returns from the service. On the first line of this method it looks for queryResult.Metadata. My Metadata is undefined and so the $.each crashes inside the jquery library. I'm not sure what this Metadata is actually for but inside my JSON endpoint I am indeed specifying transmitMetadata = true.

    Not sure if these are linked but what else could this be for and why is there no if (metadata != undefined). Is this a bug in DataContext.js?

    Wednesday, August 17, 2011 10:45 AM

Answers

  • For some reason you are using the wrong version of the Microsoft.ServiceModel.DomainServices.Hosting.dll. Make sure it is referenced from "C:\Program Files (x86)\Microsoft SDKs\RIA Services\v1.0\Toolkit\Libraries\Server\SP2\Microsoft.ServiceModel.DomainServices.Hosting.dll".

    Thanks,
    -Yavor

    Wednesday, August 17, 2011 3:06 PM

All replies

  • Looking at my returned JSON it is just simply not returning anything to do with Metadata:

    {"GetBookResult":{"TotalCount":-1,"RootResults":[{"ASIN":null,"AddedDate":"\/Date(-62135578800000-0500)\/","Author":null,"CategoryId":0,"Description":null,"Id":0,"PublishDate":"\/Date(-62135578800000-0500)\/","Title":null}]}}
    Wednesday, August 17, 2011 12:26 PM
  • For some reason you are using the wrong version of the Microsoft.ServiceModel.DomainServices.Hosting.dll. Make sure it is referenced from "C:\Program Files (x86)\Microsoft SDKs\RIA Services\v1.0\Toolkit\Libraries\Server\SP2\Microsoft.ServiceModel.DomainServices.Hosting.dll".

    Thanks,
    -Yavor

    Wednesday, August 17, 2011 3:06 PM
  • Wow, I can't believe the amount of hours I spend tracking issues doing these samples. I had been using the web platform installer to install the toolkit. When I saw the article mentioning April, and I saw May in the platform installer I simply assumed it was newer. But the toolkit is indeed May 2010! D'OH!!!! I'm surprised I even got as far as I did.

    Wednesday, August 17, 2011 3:48 PM
  • Thank you

    Wednesday, August 17, 2011 7:27 PM
  • Two other things to watch out for. Older versions had a specific DLL for the JSON implementation and this is no longer necessary. Second make sure that you are configured to transmit metadata

     

            <add name="JSON" type="Microsoft.ServiceModel.DomainServices.Hosting.JsonEndpointFactory, Microsoft.ServiceModel.DomainServices.Hosting, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" transmitMetadata="true" />

     

    Thursday, August 18, 2011 5:54 PM
  • Thanks for sharing your experiences here... let me know if you hit further issues.

    Thanks,
    -Yavor

    Thursday, August 18, 2011 6:07 PM
  • I am still having the "metadata is null or undefined" error even after pointing the project reference to the SP2 dll and making sure I have:

    <add name="json" transmitMetadata="true" type="Microsoft.ServiceModel.DomainServices.Hosting.JsonEndpointFactory, Microsoft.ServiceModel.DomainServices.Hosting, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" />

    in my web.config

    What else could be causing this to happen?

    Saturday, January 07, 2012 2:38 PM
  • One problem that I had was that there was at one time a separate DLL for implementing JSON that was depricated when the functionality moved into (I think) DomainServices.Hosting. In my case there was a legacy entry in my Web.config pointing to the JSON dll that had to be removed.

    There is a low probability that this is your issue but it is easy to check for.

    At one point (I don't even remember which version I was using) there was a misleading message that came from the client-side javascript implementation. You can check with Fiddler to see if it is actually flowing to the client - if so you will see it tacked on to the end of the response.

    In the end, I didn't have the JavaScript chops to get the client working and I found that the metadata was too big for 3G so I dropped back and used the JSON with pure AJAX on the client and bound it to JQGrid.

    Here is what Auth looked like:

    function Auth() {
        var _username = $(UserName).val();
        var _password = $(Password).val();
        var loginParameters = JSON.stringify({ 'userName': _username, 'password': _password, 'isPersistent': 'true', 'customData': '' });
        var result;
    
        //Create jQuery ajax request
        $.support.cors = true;       // allows cross-site scripting
        var Params = {}
        Params.type = "POST";
        Params.url = authUrl;
    
        Params.dataType = "json";
        Params.data = loginParameters;
        Params.contentType = "application/json"
        Params.success = function (data) {
            for (i in data.LoginResult.RootResults) {
                result = data.LoginResult.RootResults[i];
                setCookie("currentUser", result.Name, 1);
            }
            if (result != null) {
                $("#AccountInfo").fadeOut(500, null);
                window.location.href = "OrderGrid.html";
            }
            else {
                $("#AccountInfo").append("<p><font color='red'>Error while logging. Check username or password.</font></p>");
            }
        }
        Params.error = function (jqXHR, textStatus, errorThrown) {
            alert(errorThrown);
        }
    
    
        //Make the ajax request
        $.ajax(Params);
    }
    

    And Query

        $.support.cors = true;  // cross site scripting support
        var Params = {}
        Params.type = "POST";
        Params.url = patientsUrl + "GetMatchingPatients";
    
        Params.dataType = "json";
        Params.data = loginParameters;
        Params.contentType = "application/json"
        Params.success = function (data) {
            var fp = document.getElementById("foundPatients");
            fp.options.length = 0;
    
            if (data.GetMatchingPatientsResult) {
                if (!(data.GetMatchingPatientsResult[0]))
                    alert("No patients found that match string: " + patientString);
                else {
                    patients = data.GetMatchingPatientsResult;
                    for (i in patients) {
                        if (i == parseInt(i)) {
                            result = patients[i];
                            fp.options.add(new Option(result.PatientFirstName + " " + result.PatientLastName, result));
                        }
                    }
                    currentPatient = patients[0];
                    NewPatient();
                }
            }
        }
    
        //Make the ajax request
        $.ajax(Params);

    And Submit Changes

    function InsertOrder(order) { 
        var orders = [];
        var changeSet = { 'Entity': order, 'Operation': 'Insert' };
        var data = JSON.stringify(changeSet);
    
        $.support.cors = true;  // cross site scripting support
        var Params = {}
        Params.type = "POST";
        Params.url = "http://portal.com/ClientBin/PortalApp-Web-Services-PortalDomain.svc/json/SubmitChanges";
        Params.dataType = "json";
        Params.data = data;
        Params.contentType = "application/json"   
    
        Params.success = function (data) {
            if (data) {        
               
            }
        }
    
        Params.error = function (jqXHR, textStatus, errorThrown) {
            alert(errorThrown);
        }
    
    
        //Make the ajax request
        $.ajax(Params);
    }

    I am sure that to someone with some JS experience these are embarassing but they got me started.

    Don Rule
    http://translationalsoftware.com

    Saturday, January 07, 2012 3:57 PM
  • I am not sure what to look for knowing if there is a legacy dll in the web.config. I am using the web.config as it came in the download for the Big Shelf - Completed solution at:

    http://download.codeplex.com/Download?ProjectName=wcf&DownloadId=281359

    I have that, and:

    RIA Services 1.0 SP2: http://www.microsoft.com/download/en/details.aspx?displaylang=en&id=28357

    RIA Services Toolkit: http://www.microsoft.com/download/en/details.aspx?displaylang=en&id=26939

    I do not get the error when I use Firefox as my browser, but I do get the error when I use stock IE8. I want to use IE8 as my browser so I can use Visual Studio's IDE to do my javascript debugging.

    If it helps, this is using jquery 1.6.3.

    Saturday, January 07, 2012 6:16 PM
  • I just looked at the sample code and the problem that I had is not in the web.config. It would be in the Endpoints section. In my case I think that I had tweaked my web.config based on an earlier sample that included the JSON Dll.

    The fact that it is browser specific implies to me that the issue is at the client and not what is coming over the wire but it is always helpful to use Fiddler to see what the server is emitting. If it has metatada it will be really obvious in the response messages (in my case really really obvious).

    Is there any chance that you are using a different box for the client and server side of things? I struggled with a lot of cross-domain issues that were sometimes different across browsers.

    You may want to step through what is happening in the FireFox (I found Chrome easier to learn) debuggers side-by-side to see how it should be working.

    Good Luck,
    Don

     

     

    Saturday, January 07, 2012 6:47 PM
  • I don't know what the problem is. The server response is coming back identically for IE and Firefox. IE breaks in the jquery code. I am running this all on one box.

    About ready to give up here. Is this supposed to work out of the box with IE8?

    Edit: Another issue is I cannot deploy this project to IIS successfully. I have made the app domain user an administrator and given that user sysadmin privileges on the local database (Sql Express) as well as given the user read/write to the application folder. However, when I try to browse the web application which I have deployed, it breaks on the line :

    if (Membership.GetAllUsers().Count == 0)

    User does not have permission to perform this action.
    Sunday, January 08, 2012 9:44 PM
  • It's really strange that this would work in Firefox for you but not in IE8.

    I wonder whether this isn't a different problem than your "metadata" one.

    If you happen to still be looking at this and can send me a JavaScript stack trace, I'd be happy to take a closer look.

    I'm the lead developer on RIA/JS...which has recently been rechristened Upshot.

    Tuesday, January 31, 2012 6:34 PM