使用Wcf服务找不到Angular JS应用程序获取方法返回404

时间:2017-12-14 03:24:12

标签: javascript c# angularjs wcf

我正在开发wcf休息服务,我将它用于角度js应用程序。我正在尝试根据帐号检索用户帐户信息。当我使用帐号调用方法形式的本地主机时,我以jSON格式从sql数据库获取数据。但是,当我尝试从角度js应用程序调用该方法时,我在Google Chrome控制台窗口中出现以下错误,并且未在网页中显示数据。

获取http://localhost:52098/HalifaxIISService.svc/GetAccountDetails?Account_Number15 404(未找到)。

我检查网络标签及其在响应部分中的显示结束点未找到。

这是界面。

    [OperationContract]
   [WebInvoke(Method = "GET",
   RequestFormat = WebMessageFormat.Json,
   ResponseFormat = WebMessageFormat.Json,
   //BodyStyle = WebMessageBodyStyle.Bare,
    UriTemplate = "/GetAccountDetails/{Account_Number}")]
    string  GetAccountDetails(string Account_Number);

这是实施。

 public string GetAccountDetails(string Account_Number)
        {
                //Convert.ToInt32(Account_Number);
            List<object> customers = new List<object>();
            string sql = "SELECT * FROM Current_Account_Details WHERE Account_Number=@Account_Number";
            using (SqlConnection conn = new SqlConnection())
            {
                conn.ConnectionString = ConfigurationManager.ConnectionStrings["DBCS"].ConnectionString;
                using (SqlCommand cmd = new SqlCommand(sql))
                {
                    cmd.Parameters.AddWithValue("@Account_Number",Account_Number);
                    cmd.Connection = conn;
                    conn.Open();
                    using (SqlDataReader sdr = cmd.ExecuteReader())
                    {
                        while (sdr.Read())
                        {

                            customers.Add(new
                            {
                                Account_Number = sdr["Account_Number"],
                                Account_Creation_Date = sdr["Account_Creation_Date"],
                                Account_Type = sdr["Account_Type"],
                                Branch_Sort_Code = sdr["Branch_Sort_Code"],
                                Account_Fees = sdr["Account_Fees"],
                                Account_Balance = sdr["Account_Balance"],
                                Over_Draft_Limit = sdr["Over_Draft_Limit"],




                            });
                        }
                    }
                    conn.Close();
                }

                return (new JavaScriptSerializer().Serialize(customers));
            }

        }
    }
}

这是脚本代码。

var app = angular.module("WebClientModule", [])
    .controller('Web_Client_Controller', ["$scope", 'myService', function ($scope, myService) {
        var Account_Number = $scope.Account_Number;
        $scope.search = function (Account_Number) {
            var promiseGetSingle = myService.getbyAccount_Number(Account_Number);

            promiseGetSingle.then(function (pl) {
                var res = pl.data;
                $scope.Account_Number = res.Account_Number;
                $scope.Account_Creation_Date = res.Account_Creation_Date;
                $scope.Account_Type = res.Account_Type;
                $scope.Branch_Sort_Code = res.Branch_Sort_Code;
                $scope.Account_Fees = res.Account_Fees;
                $scope.Account_Balance = res.Account_Balance;
                $scope.Over_Draft_Limit = res.Over_Draft_Limit;

                //   $scope.IsNewRecord = 0;
            },
                function (errorPl) {
                    console.log('failure loading Employee', errorPl);

                });
        }

    }]);




app.service("myService", function ($http) {

        this.getbyAccount_Number = function (Account_Number) {
            return $http.get("http://localhost:52098/HalifaxIISService.svc/GetAccountDetails?Account_Number" + Account_Number);
        };

   })

这是HTML。

@{
    Layout = null;
}

<!DOCTYPE html>

<html ng-app="WebClientModule">
<head>
    <meta name="viewport" content="width=device-width" />

    <title>AccountBalance</title>
    <script src="~/Scripts/angular.min.js"></script>
    <script src="~/RegistrationScript/AccountBalance.js"></script>

</head>
<body>
    <div data-ng-controller="Web_Client_Controller">
        Enter Account_Number: <input type="text" ng-model="Account_Number" />
        <input type="button"  value="search" ng-click="search(Account_Number)" />

            <table id="tblContainer"    ng-show="IsVisible" >
                <tr>
                    <td>
                        <table style="border: solid 2px Green; padding: 5px;">
                            <tr style="height: 30px; background-color: skyblue; color: maroon;">
                                <th></th>
                                <th>Account Number</th>
                                <th>Account Creation Date</th>
                                <th>Account Type</th>
                                <th>Branch Sort Code</th>
                                <th>Account Fees</th>
                                <th>Account Balance</th>
                                <th>Over Draft Limit</th>

                                <th></th>
                                <th></th>
                            </tr>
                            <tbody data-ng-repeat="user in Users">
                                <tr>
                                    <td></td>
                                    <td><span>{{user.Account_Number}}</span></td>
                                    <td><span>{{user.Account_Creation_Date}}</span></td>
                                    <td><span>{{user.Account_Type}}</span></td>
                                    <td><span>{{user.Branch_Sort_Code}}</span></td>

                                    <td><span>{{user.Account_Fees}}</span></td>
                                    <td><span>{{user.Account_Balance}}</span></td>
                                    <td><span>{{user.Over_Draft_Limit}}</span></td>
                                    <td>

                                </tr>
                            </tbody>
                        </table>
                    </td>
                </tr>
                <tr>
                    <td></td>
                </tr>
                <tr>
                    <td>

                        <div style="color: red;">{{Message}}</div>

                    </td>
                </tr>
            </table>
        </div>
        </body>


</html>
<script src="~/RegistrationScript/AccountBalance.js"></script>

以下是我使用帐号参数调用方法时的屏幕截图。 enter image description here

这是我点击提交按钮时的屏幕截图。 enter image description here

以下是网络标签中的屏幕截图。

enter image description here

0 个答案:

没有答案