After setting up an AMSX Web Service, everything seemed to be running smoothly when accessing the specified URL:
public class ExpenseService : System.Web.Services.WebService
{
[WebMethod]
public void Get()
{
List<Expense> expenses = new List<Expense>();
expenses.Add(new Expense(1, "Netflix", "Netflix", 20.00, new DateTime()));
expenses.Add(new Expense(2, "Spotify", "Spotify", 14.90, new DateTime()));
JavaScriptSerializer js = new JavaScriptSerializer();
Context.Response.Write(js.Serialize(expenses));
}
}
https://i.sstatic.net/ymD9l.png
However, a problem arises when attempting to make a GET request from my AngularJS controller using $http:
var app = angular.module("app", ["ngRoute"]);
app.config(function ($routeProvider) {
$routeProvider.when("/home", {
templateUrl: "Pages/Home.html",
controller: "homeController"
})
});
app.controller("homeController", function ($http) {
var self = this;
$http.get("ExpenseService.asmx/Get")
.then(function (response) {
self.expenses = response.data;
})
});
The console displays an error message as follows:
https://i.sstatic.net/lEDhT.png
Furthermore, clicking on the link within the error message (highlighted in the image above) results in encountering an error on the page:
https://i.sstatic.net/Jd9hH.png
It's worth noting that manual access of the JSON data through entering the URL in a browser still works fine.