Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/315.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript Wcf服务不从Angular JS应用程序接收参数值_Javascript_C#_Angularjs_Wcf_Ado.net - Fatal编程技术网

Javascript Wcf服务不从Angular JS应用程序接收参数值

Javascript Wcf服务不从Angular JS应用程序接收参数值,javascript,c#,angularjs,wcf,ado.net,Javascript,C#,Angularjs,Wcf,Ado.net,我正在将Wcf服务消费到AngularJS应用程序中,但它并没有按照我的预期工作。我正在尝试使用Sql事务处理方法将钱从一个帐户发送到另一个帐户。当我在AngularJS应用程序中单击submit按钮时,它无法将输入值发布到wcf服务。我将断点放在wcf服务中,它不接收任何值 这是一个名为Money Transfer的本地类 { [DataContract] public class MoneyTransfer { string sender_accoun

我正在将Wcf服务消费到AngularJS应用程序中,但它并没有按照我的预期工作。我正在尝试使用Sql事务处理方法将钱从一个帐户发送到另一个帐户。当我在AngularJS应用程序中单击submit按钮时,它无法将输入值发布到wcf服务。我将断点放在wcf服务中,它不接收任何值

这是一个名为Money Transfer的本地类

{
    [DataContract]
    public class MoneyTransfer
    {
        string sender_account_no;
        string sender_name;
        string sender_sort_code;
        string amount1;
        string transcation_type;
        string date;
        string receiver_account_no;
        string receiver_name;
        string receiver_sort_code;
        string amount2;
        string transcation_type1;
        string date1;

        [DataMember]
        public string Sender_Account_No
        {
            get { return sender_account_no; }
            set { sender_account_no = value; }


        }
        [DataMember]
        public string Sender_Name
        {
            get { return sender_name; }
            set { sender_name = value; }

        }
        [DataMember]
        public string Sender_Sort_Code
        {
            get { return sender_sort_code; }
            set { sender_sort_code = value; }
        }
        [DataMember]
        public string Amount
        {
            get { return amount1; }
            set { amount1 = value; }
        }
        [DataMember]
        public string Transcation_Type
        {
            get { return transcation_type; }
            set { transcation_type = value; }

        }
        [DataMember]
        public string Date
        {
            get { return date; }
            set { date = value; }


        }
        [DataMember]
        public string Receiver_Account_No
        {
            get { return receiver_account_no; }
            set { receiver_account_no = value; }


        }
        [DataMember]
        public string Receiver_Name
        {
            get { return receiver_name; }
            set { receiver_name = value; }

        }
        [DataMember]
        public string Receiver_Sort_Code
        {
            get { return receiver_sort_code; }
            set { receiver_sort_code = value; }
        }
        [DataMember]
        public string Amount1
        {
            get { return amount2; }
            set { amount2 = value; }
        }
        [DataMember]
        public string Transcation_Type1
        {
            get { return transcation_type1; }
            set { transcation_type1 = value; }

        }
        [DataMember]
        public string Date1
        {
            get { return date1; }
            set { date1 = value; }


        }

    }
}
这是我的界面

 [OperationContract]
        [WebInvoke(Method = "POST",
        RequestFormat = WebMessageFormat.Json,
        ResponseFormat = WebMessageFormat.Json,
        UriTemplate = "/MoneyTranfer")]
       bool  MoneyTranfer(MoneyTransfer mopneyTransfer);
这是我的实现

  public bool MoneyTranfer(MoneyTransfer mopneyTransfer)
            {

                int amount = System.Convert.ToInt32(mopneyTransfer.Amount);
                int amount1 = System.Convert.ToInt32(mopneyTransfer.Amount1);

                SqlConnection cn = new SqlConnection(ConnectionString);
                string sql = "select Account_Balance from Current_Account_Details where Account_Number='" + mopneyTransfer.Sender_Account_No + "'";

                SqlCommand cmd = new SqlCommand(sql, cn);
                if (cn.State == ConnectionState.Closed)
                    cn.Open();

                //amount = int.Parse(cmd.ExecuteScalar().ToString());

                if (amount > 0)
                {
                    int b;
                    int b1;
                    SqlCommand cmd1 = new SqlCommand();
                    SqlTransaction trans;
                    if (cn.State == ConnectionState.Closed)
                        cn.Open();
                    trans = cn.BeginTransaction();

                    cmd1.Connection = cn;
                    cmd1.CommandType = CommandType.Text;
                    cmd1.Transaction = trans;
                    cmd1.CommandText = "update Current_Account_Details set Account_Balance=Account_Balance-'" + mopneyTransfer.Amount + "' where Account_Number='" + mopneyTransfer.Sender_Account_No + "'";
                    b = cmd1.ExecuteNonQuery();

                    cmd1.CommandText = "update Reward_Account_Details set Account_Balance=Account_Balance+'" + mopneyTransfer.Amount1 + "' where Account_Number='" + mopneyTransfer.Receiver_Account_No + "'";
                    b1 = cmd1.ExecuteNonQuery();
                    if (b == 1 && b1 == 1)
                    {
                        trans.Commit();
                        using (SqlConnection con = new SqlConnection(ConnectionString))
                        {
                            //Create the SqlCommand object
                            //Create the SqlCommand object
                            SqlCommand cmd3 = new SqlCommand("Current_Account_WITHDRAR", con);
                            //Specify that the SqlCommand is a stored procedure
                            cmd3.CommandType = System.Data.CommandType.StoredProcedure;

                            //Add the input parameters to the command object
                            cmd3.Parameters.AddWithValue("@Account_Number", mopneyTransfer.Sender_Account_No);
                            cmd3.Parameters.AddWithValue("@Account_Holder_Name", mopneyTransfer.Sender_Name);
                            cmd3.Parameters.AddWithValue("@Amount", mopneyTransfer.Amount);


                            cmd3.Parameters.AddWithValue("@Sort_Code", mopneyTransfer.Sender_Sort_Code);
                            cmd3.Parameters.AddWithValue("@Transcation_Type", mopneyTransfer.Transcation_Type);
                            cmd3.Parameters.AddWithValue("@Date", mopneyTransfer.Date);

                            SqlCommand cmd2 = new SqlCommand("Reward_Account_Dposit", con);
                            //Specify that the SqlCommand is a stored procedure
                            cmd2.CommandType = System.Data.CommandType.StoredProcedure;

                            //Add the input parameters to the command object
                            cmd2.Parameters.AddWithValue("@Account_Number", mopneyTransfer.Receiver_Account_No);
                            cmd2.Parameters.AddWithValue("@Account_Holder_Name", mopneyTransfer.Receiver_Name);
                            cmd2.Parameters.AddWithValue("@Amount", mopneyTransfer.Amount1);


                            cmd2.Parameters.AddWithValue("@Sort_Code", mopneyTransfer.Receiver_Sort_Code);
                            cmd2.Parameters.AddWithValue("@Transcation_Type", mopneyTransfer.Transcation_Type1);
                            cmd2.Parameters.AddWithValue("@Date", mopneyTransfer.Date1);




                            //Open the connection and execute the query

                            con.Open();
                            cmd2.ExecuteNonQuery();

                            cmd3.ExecuteNonQuery();
                            return true;
                            //con.Close();
                        }

                    }
                    else
                        trans.Rollback();
                    return false;
                }
                return false;

            }
下面是脚本代码

/// <reference path="../angular.min.js" />  



var app = angular.module("WebClientModule", [])

    .controller('Web_Client_Controller', ["$scope", 'myService', function ($scope, myService) {

        $scope.OperType = 1;

        //1 Mean New Entry  

        //To Clear all input controls.  
        function ClearModels() {
            $scope.OperType = 1;

            $scope.Sender_Account_No = "";
            $scope.Serder_Name = "";
            $scope.Sender_Sort_Code = "";
            $scope.Amount_to_Send = "";
            $scope.Transcation_Type = "";
            $scope.Date = "";

            $scope.Reciver_Account_No = "";
            $scope.Reciver_Name = "";
            $scope.Reciver_Sort_Code = "";
            $scope.Amount_to_Recive = "";
            $scope.Transcation_Type1 = "";
            $scope.Date1 = "";

        }


        $scope.createuser = function () {
            var User = {
                Sender_Account_No: $scope.Sender_Account_No,
                Serder_Name: $scope.Serder_Name,
                Sender_Sort_Code: $scope.Sender_Sort_Code,
                Amount_to_Send: $scope.Amount_to_Send,
                Transcation_Type: $scope.Transcation_Type,
                Date:$scope.Date ,

                Reciver_Account_No: $scope.Reciver_Account_No,
                Reciver_Name: $scope.Reciver_Name,
                Reciver_Sort_Code: $scope.Reciver_Sort_Code ,
                Amount_to_Recive: $scope.Amount_to_Recive,
                Transcation_Type1: $scope.Transcation_Type1,
                Date1:$scope.Date1 

            };
            if ($scope.OperType === 1) {
                var promisePost = myService.post(User);
                promisePost.then(function (pl) {
                    $scope.Id = pl.data.Id;
                    $scope.msg = "Operation is successful";


                }, function (err) {
                    $scope.msg = "Operation is failed !";
                    console.log("Some error Occured" + err);
                });
            } else {

            }

        };



    }]);

app.service("myService", function ($http) {
    //Create new record  
    this.post = function (User) {
        var request = $http({
            method: "post",
            url: "http://localhost:52098/HalifaxIISService.svc/MoneyTranfer",
            data: JSON.stringify(User)
        });
        return request;

    }

})
//
var app=angular.module(“WebClient模块”,[])
.controller('Web_客户端_控制器',[“$scope”,'myService',函数($scope,myService){
$scope.OperType=1;
//1是指新条目
//清除所有输入控件。
函数ClearModels(){
$scope.OperType=1;
$scope.Sender_Account_No=“”;
$scope.Serder_Name=“”;
$scope.Sender_Sort_Code=“”;
$scope.Amount_to_Send=“”;
$scope.transaction_Type=“”;
$scope.Date=“”;
$scope.Reciver_Account_No=“”;
$scope.Reciver_Name=“”;
$scope.Reciver_Sort_Code=“”;
$scope.Amount_to_Recive=“”;
$scope.transaction_Type1=“”;
$scope.Date1=“”;
}
$scope.createuser=函数(){
变量用户={
发件人帐户号:$scope.Sender帐户号,
Serder_Name:$scope.Serder_Name,
发件人\排序\代码:$scope.Sender\排序\代码,
金额至发送:$scope.Amount至发送,
事务处理类型:$scope.transaction类型,
日期:$scope.Date,
收款人账号:$scope.Reciver账号,
接收器名称:$scope.Reciver\u名称,
接收排序代码:$scope.Reciver\u Sort\u Code,
金额到收款:$scope.Amount到收款,
交易类型1:$scope.transaction交易类型1,
Date1:$scope.Date1
};
如果($scope.OperType==1){
var promisePost=myService.post(用户);
promisePost.then(功能(pl){
$scope.Id=pl.data.Id;
$scope.msg=“操作成功”;
},函数(err){
$scope.msg=“操作失败!”;
console.log(“发生了一些错误”+err);
});
}否则{
}
};
}]);
app.service(“myService”,函数($http){
//创造新记录
this.post=函数(用户){
var请求=$http({
方法:“张贴”,
url:“http://localhost:52098/HalifaxIISService.svc/MoneyTranfer",
数据:JSON.stringify(用户)
});
返回请求;
}
})
下面是调试模式的屏幕截图

这是我运行应用程序时的屏幕截图

任何反馈或建议都将受到海利公司的欢迎。谢谢