通过Angular $ http POST将多个参数发送到SOAP服务

时间:2016-11-16 11:27:19

标签: jquery asp.net angularjs soap

我正在创建一个基本的Angular js应用程序。有一个简单的基本形式有4个参数。现在我希望将此表单的详细信息保存在Access数据库中。

以下是我的SOAP服务方法代码:

[WebMethod]
        public void RegisterMember(string strFirstName, string strLastName, string strEmailAddress, string strPassword)
        {
            try
            {
                System.Data.DataTable dt = new System.Data.DataTable();
                int rowsAffected = 0;
                StringBuilder sbQuery = new StringBuilder();
                sbQuery.Append("INSERT INTO [Members]([FirstName],[LastName],[EmailAddress],[Password],[InsertedOrUpdatedDateTime],[Active]) VALUES (");
                sbQuery.Append(string.Format("\'{0}\',\'{1}\',\'{2}\',\'{3}\',\'{4}\',\'{5}\');", strFirstName, strLastName,
                               strEmailAddress, strPassword, DateTime.Now.ToShortDateString(), "No"));
                Helpers.DAOHelper.InsertData(out rowsAffected, sbQuery.ToString());
                if (rowsAffected > 0)
                {
                    HttpContext.Current.Response.Write(rowsAffected.ToString());
                }
                else
                {
                    HttpContext.Current.Response.Write("Failed to Register");
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }

以下是我的Angular js Code。从控制器调用自定义服务。

loginApp.factory("CS_RegisterMember", function ($http, $q, $log) {
    return {
        "RegisterMember": function (FirstName, LastName, EmailAddress, Password) {
            var RegisterMemberResp = $q.defer();
            var a = {
                strFirstName: FirstName, strLastName: LastName,
                strEmailAddress: EmailAddress, strPassword: Password
            };

            alert(a);
            $http({
                url: "http://localhost:61784/Employee.asmx/RegisterMember",
                method: "POST",
                headers: { 'Content-Type': 'application/x-www-form-urlencoded' },
                params: a
            }).then(function (resp) {
                RegisterMemberResp.resolve(resp);
            },
            function (e_resp) {
                $log.error(e_resp);
                RegisterMemberResp.reject(e_resp);
            })
            return RegisterMemberResp.promise;
        }
    }
});

但是,当我运行这个时,我会收到以下错误:

System.InvalidOperationException: Request format is invalid: 
at System.Web.Services.Protocols.HttpServerProtocol.ReadParameters()
   at System.Web.Services.Protocols.WebServiceHandler.CoreProcessRequest()

我正在尝试一周以来。在各种博客上搜索但没有得到解决方案。请帮帮我。

0 个答案:

没有答案