ashok kumar

ashok kumar

  • NA
  • 89
  • 36.1k

unable to retreive data from WCF service from jquery

Aug 7 2013 1:45 AM
Hi All,
        Iam using an wcf web service to retrieve value from database ,iam calling it from jquery ajax call,the problem is getPollDetails.ModelMake is null or not an object.

aspx code:

var varType;
         var varUrl;
         var varData;
         var varContentType;
         var varDataType;
         var varProcessData;
         //Generic function to call AXMX/WCF  Service        
         function CallService() {
             $.ajax({
                 type: varType, //GET or POST or PUT or DELETE verb
                 url: varUrl, // Location of the service
                 data: varData, //Data sent to server
                 contentType: varContentType, // content type sent to server
                 dataType: varDataType, //Expected data format from server
                 processdata: varProcessData, //True or False
                 success: function (msg) {//On Successfull service call
                     ServiceSucceeded(msg);
                 },
                 error: alert('not working')// When Service call fails
             });
         }
         
         //Data Available
         function ServiceSucceeded(result) {
            
             $('span[id=lblmakemodels]').text(result.getPollDetails.ModelMake);-->when i keep break point on (result.getPollDetails.ModelMake) value is coming here also.
             alert(result.getPollDetails.ModelMake);

         }


         function PollingDataJSON(selectdata) {
             alert(selectdata);
             varType = "POST";
             varUrl = "../HttpHandler/GetPollingDataService.svc/getPollDetails";
            
             varData =  JSON.stringify({
                 vehicleno: selectdata,
                                });
             varContentType = "application/json; charset=utf-8";
             varDataType = "json";
             varProcessData = true;
             CallService();
         }


wcf code:
 [AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)]
    [ServiceBehavior(IncludeExceptionDetailInFaults = true)]
    [DataContract]
    public class GetPollingDataService : IGetPollingDataService
    {
      [DataMember]
        public string ModelMake;
}

 public GetPollingDataService getPollDetails(string vehicleno)
        {

if (dr.Read() != null)
                {
                    objdet.ModelMake = dr["YearMake"].ToString();
                    dr.Close();
                    return objdet;
                }
}
when i keep the break point values is retreiving in objdet.ModelMake.



Answers (12)