0

I am trying to get the data from the Web Service by using the POST Method.

This is my javascript to get the data

            var s = {
                            OpportunityID: 6
                        }

            $.ajax({
                type: "POST",
                url: "/ws/WSServices.svc/GetStudentTimeTableByOpportunityID",
                data: JSON.stringify(s),
                contentType: "application/json",
                dataType: "JSON",
                async: false,
                success: function (data) {
                    console.log(data);
                }
            });

Here is my Server Side code

    [OperationContract]
    [WebInvoke(Method = "POST", ResponseFormat = WebMessageFormat.Json, RequestFormat= WebMessageFormat.Json)]
    public List<DataEntity.CalendarEvent> GetStudentTimeTableByOpportunityID(int OpportunityID)
        {
            Utils.Debug("InWebService : " + OpportunityID);
            List<DataEntity.CalendarEvent> events = new List<DataEntity.CalendarEvent>();

            //populate events code

            return events;
        }

The problem is that it is not running even the first line of code and always showing that there is a Bad Request (400). Please see the screenshots in FireBug

enter image description here

I checked it and it shows the correct data in JSON format and I couldn't figure out why it is showing as 400 Error.

Please help me to highlight how I could invoke the Post Request to WCF Webservices by using JQUERY AJAX.

TTCG
  • 8,805
  • 31
  • 93
  • 141
  • Q: Why WCF instead of WebAPI or just web controller actions? It's not like you will be using any of special features of WCF from Ajax anyway. – iCollect.it Ltd Oct 27 '14 at 11:10
  • Are you sure , you have proper binding, endpoint set for WCF, are you able to post to WCF using Fiddler?else enable tracing - http://msdn.microsoft.com/en-us/library/ms733025(v=vs.110).aspx , and check logs – Arindam Nayak Oct 27 '14 at 11:38

0 Answers0