AngularJS Services调用.asmx webservice - TypeError:无法将对象转换为原始值

时间:2017-02-03 05:17:14

标签: javascript angularjs web-services http asmx

我很遗憾地问这个问题。如果我的问题不明确,我很抱歉。我试图从我的AngularJS服务中调用.asmx webservice。

在我的AngularJS服务中,我有以下代码片段:

    .factory('BoothDesignatedCoordsService', ['$http',function ($http) {


return {
    // Might retrieved from db eventually
    fnGetBoothDesignatedCoords: function (strBoothName, intFloorPlanID) {
        try
        {
            var JSONObj = {
                BoothName: strBoothName,
                FloorPlanID: intFloorPlanID
            };
            var sendToWS = JSON.stringify(JSONObj)
        }
        catch(e)
        {
            alert("error from fnGetBoothDesignatedCoords " + e)
        }



        $http.post('http://localhost:4951/wsIPS.asmx?op=fnGetBoothDesignatedCoords',  sendToWS).then(function (response) {
            if (response.data)
                alert("Post Data Submitted Successfully!");
        }, function (response) {
            alert("Service not Exists");
           alert(response.status);
           alert(response.statusText);
            alert(response.headers());
        });


    }

}

 }])

在我的.asmx文件中,我有以下代码段:

       [WebMethod(EnableSession = true)]
    [ScriptMethod(UseHttpGet = true)]

          public void fnGetBoothDesignatedCoords(string objJSONRequest)
    {
        wsIPS objRequest = JsonConvert.DeserializeObject<wsIPS>(objJSONRequest);
        string strBoothName = objRequest.ClientBoothName;
        string strFloorPlanID = objRequest.ClientFloorPlanID;
        int intFloorPlanID = int.Parse(strFloorPlanID.ToString());


        double[] arrBoothDesignatedCoords = new double[0];
        string strConnectionString = ConfigurationManager.ConnectionStrings["IPSConnection"].ConnectionString;
        SqlConnection myConnect = new SqlConnection(strConnectionString);
        string strCommandText = "SELECT DesignatedCoords FROM Booth WHERE Name = @Name AND FloorPlanID = @FloorPlanID";
        SqlCommand selectCmd = new SqlCommand(strCommandText, myConnect);
        selectCmd.Parameters.AddWithValue("@Name", strBoothName);
        selectCmd.Parameters.AddWithValue("@FloorPlanID", intFloorPlanID);
        myConnect.Open();
        SqlDataReader reader = selectCmd.ExecuteReader();
        if (reader.Read())
        {
            string strBoothDesignatedCoords = reader["DesignatedCoords"].ToString();
          arrBoothDesignatedCoords = Array.ConvertAll(strBoothDesignatedCoords.Split(','), double.Parse);
        }
        myConnect.Close();
        JavaScriptSerializer js = new JavaScriptSerializer();

        Context.Response.Write(js.Serialize(arrBoothDesignatedCoords));
    }

}
}

注意:我的.asmx网络服务正在运行,因此我可以使用该网址直接在我的本地计算机上访问它。

但是,我收到警告错误,说&#34;服务不存在&#34;,错误代码是500,这是内部服务器错误。并且控制台日志给出了这个错误:TypeError:无法将对象转换为原始值。有人可以帮助我吗?

这是我的.asmx网络服务及其网址的屏幕截图:

enter image description here

enter image description here

0 个答案:

没有答案