使用AngularJS $ http.post将对象传递给.Net asmx

时间:2015-08-28 20:04:58

标签: .net angularjs vb.net web-services asmx

所以我试图将一个javascript对象从Angular $ http.post传递给.net Web服务。我有这个工作的另一种网络方法,如此

var GetLeadTimeline = function($http,idLead){return $http.post('/admin/leads/LeadUpdates.asmx/GetLeadTimeline', {idLead: idLead});};

但该方法只需要一个整数作为id

我想现在收到一个对象。 我收到500错误,有人能指出我指示我做错了什么吗?

模板中的代码

<button id="btnAddReminder" data-id="" data-name="" type="button" class="btn btn-primary" ng-click="AddNewReminder(l.idLead, l.FirstName + l.LastName)">

AngularJS - 功能

$scope.AddNewReminder = function(idlead, name) {
            var dataObj = { 
                ReminderContent: name, 
                ReminderDT: $scope.Reminder.DateTime,
                idLead: idlead
            };
            var ReminderPromise = LeadsServiceTest.UpdateReminder($http,dataObj);
            ReminderPromise.then(function(response) {
                    //Do something
            });
        }

AngularJS - 服务

 myLeadDashboard.factory('LeadsServiceTest',[function(){
        var UpdateReminder = function($http,dataObj){return $http.post('/admin/leads/LeadUpdates.asmx/AddReminder', dataObj);};
        return {
            UpdateReminder:UpdateReminder                
        };
    }]);

.Net Object Class

 Public Class ReminderFields
    Public ReminderContent As String = ""
    Public ReminderDT As String = ""
    Public idLead As Integer = 0
End Class

.Net方法

 <WebMethod(EnableSession:=True)> _
<ScriptMethod(ResponseFormat:=ResponseFormat.Json, UseHttpGet:=True, XmlSerializeString:=False)>
Public Function AddReminder(ByVal value As ReminderFields) As UpdateResponse
    Dim response As New RemindersResponse
    Dim NewNotifcation As New Agent.Notifications
    NewNotifcation.Subject = value.ReminderContent
    NewNotifcation.TimeStamp = CDate(value.ReminderDT).ToUniversalTime.Subtract(#1/1/1970#).TotalSeconds
    NewNotifcation.idLead = value.idLead
    NewNotifcation.idNotification = 0
    NewNotifcation.Save()
    response.Success = True
    Return response
End Function

0 个答案:

没有答案