mardi 14 juin 2016

Unable to call webservice function angularjs

Unable to call webservice function from angularjs controller. It is accessing the file but function is not accessible. Errors:

  1. server responded with a status of 500 (Internal Server Error)
  2. System.InvalidOperationException:Web Service method name is not valid. at System.Web.Services.Protocols.HttpServerProtocol.Initialize() at System.Web.Services.Protocols.ServerProtocolFactory.Create(Type type, HttpContext context, HttpRequest request, HttpResponse response, Boolean& abortProcessing)

    namespace AngularJSTesting.App{

    [WebService(Namespace = "")]
    [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
    // To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the following line. 
    public class WebService2 : System.Web.Services.WebService
        string connectionString = System.Configuration.ConfigurationManager.ConnectionStrings["TextItConnectionString"].ToString();
        [ScriptMethod(ResponseFormat = ResponseFormat.Json)]
        public string FetchData()
            DataTable dt = new DataTable();
            using (SqlConnection con = new SqlConnection(connectionString))
                using (SqlCommand cmd = new SqlCommand("select UserName, Name, Email, PhoneNumber from new_users where UserId < 11 order by UserId asc ", con))
                    SqlDataAdapter da = new SqlDataAdapter(cmd);
                    System.Web.Script.Serialization.JavaScriptSerializer serializer = new System.Web.Script.Serialization.JavaScriptSerializer();
                    List<Dictionary<string, object>> rows = new List<Dictionary<string, object>>();
                    Dictionary<string, object> row;
                    foreach (DataRow dr in dt.Rows)
                        row = new Dictionary<string, object>();
                        foreach (DataColumn col in dt.Columns)
                            row.Add(col.ColumnName, dr[col]);
                    return serializer.Serialize(rows);
       // [ScriptMethod(ResponseFormat = ResponseFormat.Json)]
        public static string read()
            return "test";


js file

'use strict';

app.controller('aboutController', function ($scope, $http) {
$scope.message = "Now viewing About!";

var url = '';
           .success(function (data) {
               $scope.users = data;

           .error(function (data) {

Aucun commentaire:

Enregistrer un commentaire