如何将WCF作为对象参数调用

时间:2017-11-11 09:40:40

标签: c# jquery wcf

我尝试通过WCF服务连接到API。如果我将值传递给尽可能多的参数,那么我是成功的,但是当我尝试将所有参数传递给创建的类时,我不能。如何使用jQuery Post方法调用它?

我的attendenceService.cs文件

[WebInvoke(ResponseFormat = WebMessageFormat.Json,
    RequestFormat = WebMessageFormat.Json,
    Method = "POST",
    BodyStyle = WebMessageBodyStyle.Bare,
    UriTemplate = "/mobileAttendance")]
List<Attendance.attendenceService.ResultClass> applyMobileAttendance(Attendance.attendenceService.MobileAttendance attObj);

我的attendenceService.svc.cs文件

public List<Attendance.attendenceService.ResultClass> applyMobileAttendance(Attendance.attendenceService.MobileAttendance attObj)
    {
    ....
    ....
    }


//Attendance.attendenceService.MobileAttendance
        [DataContract]
        [Serializable]
        public class MobileAttendance
        {
            [DataMember]
            public int companyID { get; set; }
            [DataMember]
            public int employeeID { get; set; }
            [DataMember]
            public int checkType { get; set; }
            [DataMember]
            public string timeEntry { get; set; }
            [DataMember]
            public string longitude { get; set; }
            [DataMember]
            public string latitude { get; set; }
            [DataMember]
            public string location { get; set; }
            [DataMember]
            public string locationImage { get; set; }
        }

我尝试使用以下方法调用它:

$.post("http://localhost:1915/attendenceService.svc/mobileAttendance", "{companyID:'12',employeeID:'15',checkType:'25',timeEntry:'1232',longitude:'efef',latitude:'fgdg',location:'1424',locationImage:'fdgdfg'}", function (result,status) {
            alert("success");
        });

0 个答案:

没有答案