0

I have an Web Api controller for access data from server:

public class ServicesController : ApiController
{
    [AcceptVerbs("POST")]
    public IList<TreeMenuItem> LoadMetadata()
    {
        List<TreeMenuItem> itemsMenu = new List<TreeMenuItem>();
        TreeMenuItem dataSource = new TreeMenuItem("1", "DataSources", null);
        itemsMenu.Add(dataSource);
        return itemsMenu;
    }
}

which is call by an angularJS controler:

angular.module('App').
controller('TreeMenuController', ["$scope", "$http", treeMenuController]);

function treeMenuController($scope, $http) {
var baseUrl = "api/Services/LoadMetadata";
$http.post(baseUrl)
    .then(function (result) {
        $scope.roleList = result.data;
    });

};

In browser network I have:

Request Method:POST
Status Code:200 OK
Request Headersview source
Accept:application/json, text/plain, */*
Accept-Encoding:gzip,deflate
Content-Length:2
Content-Type:application/json;charset=UTF-8

Request Payload {}

Response Headers:

HTTP/1.1 200 OK
Content-Type: application/json; charset=utf-8
Server: Microsoft-IIS/8.0
X-AspNet-Version: 4.0.30319
X-Powered-By: ASP.NET
Content-Length: 4

in Response tab: [{}].

What is wrong?

Bogdan
  • 656
  • 15
  • 25

1 Answers1

1

I make it work: The big help was the response message when I put in browser the address for accessing api services (api/Services/LoadMetadata): The error answer was in an xml file where I found that was problem with serialization of the object TreeMenuItem. The advice was to decorate with DataContract the class and DataMember the class properties - like in WCF. After I did that (was need to add reference in project to System.Runtime.Serialization), everything was perfect.

Bogdan
  • 656
  • 15
  • 25