Sandeep Kumar

Sandeep Kumar

  • 1.1k
  • 683
  • 60.7k

how to set method to wait service response

Nov 4 2022 6:48 AM

My Issue is service still processing data ,but web method which i call call service method is aborted 

 

private void Search(string time_milliseconds)
    {
        string fromdate = txtfrom.Text.Trim();
        string todate = txtto.Text.Trim();
        int dept = Convert.ToInt32(ddlResponsibleDept.SelectedValue.ToString());
        int groupnm = Convert.ToInt32(ddlGroup.SelectedValue.ToString());
        string classs = ddlClass.SelectedItem.ToString();
        int contractor = Convert.ToInt32(ddlContractor.SelectedValue.ToString());
        int areaobsevation = 0;
        int severity = Convert.ToInt32(ddlseverity.SelectedValue.ToString());
        int createdby = 1;
        int area = Convert.ToInt32(ddlArea.SelectedValue.ToString());
        int areaOfObservation = Convert.ToInt32(ddlAreaofObservation.SelectedValue.ToString());
        time_millisecond = DateTime.Now.Millisecond.ToString();
        DataTable data = new DataTable();
        CESC_BBGS_GEN_MOB_APP_SERVICE_WS.CESC_BBGS_GEN_MOB_APP_SERVICE df = new CESC_BBGS_GEN_MOB_APP_SERVICE_WS.CESC_BBGS_GEN_MOB_APP_SERVICE();
        data = df.BBGS_Get_Safety_Mis_Report(fromdate, todate, dept, areaOfObservation, classs, contractor, areaobsevation, area, severity, createdby, time_millisecond, groupnm);
        if (data.Rows.Count > 0)
        {
            txtNoofpeople.Text = data.Rows[0]["Noofpeopleobservedatsite"].ToString();
            txtGPHr.Text = data.Rows[0]["Obs_Hr_GP"].ToString();
            lblTotalMarks.Text = data.Rows[0]["Total_Cal"].ToString();
            lblYesTotalMarks.Text = data.Rows[0]["TotalCalForYes"].ToString();
            txtUAHr.Text = data.Rows[0]["Obs_Hr_UA"].ToString();
            txtPeopleWorkingsafely.Text = data.Rows[0]["Obs_Per_working_safely"].ToString();
            txtIssueclosed.Text = data.Rows[0]["Per_Issueclosed"].ToString();
            grdobservationrpt.DataSource = data;
            grdobservationrpt.DataBind();
        }
        else
        {
            grdobservationrpt.DataSource = null;
            grdobservationrpt.DataBind();
        }
    }

 

-------------------------Service Method------------------------------------

[WebMethod(CacheDuration = 60, Description = "Return MIS Report")]
    [ScriptMethod(ResponseFormat = ResponseFormat.Json)]
    public DataTable BBGS_Get_Safety_Mis_Report(string fromdt, string todt, int dept, int group, string claass, int contractor, int areaobservation, int area, int Severity, int createdby, string time_millisecond, int ObsAreaId)
    {
        DataTable Dt = new DataTable("mytable");
      //  DataTable DtReport = new DataTable();
        string RetValue = string.Empty;
        var data = string.Empty;
        try
        {

     
            using (SqlConnection con = new SqlConnection(strConnString))
            {
                using (SqlCommand cmd = new SqlCommand("VVS_BBGS_Get_Safety_ObservationDetailsReports", con))
                {
                    cmd.CommandType = CommandType.StoredProcedure;
                    cmd.Parameters.Add("@FromDate", SqlDbType.NVarChar).Value = fromdt;
                    cmd.Parameters.Add("@ToDate", SqlDbType.NVarChar).Value = todt;
                    cmd.Parameters.Add("@Dept", SqlDbType.Int).Value = dept;
                    cmd.Parameters.Add("@GroupID", SqlDbType.Int).Value = group;
                    cmd.Parameters.Add("@classs", SqlDbType.NVarChar).Value = claass;
                    cmd.Parameters.Add("@ContractorID", SqlDbType.Int).Value = contractor;
                    cmd.Parameters.Add("@AreaOfObserv", SqlDbType.Int).Value = areaobservation;
                    cmd.Parameters.Add("@AreaID", SqlDbType.Int).Value = area;
                    cmd.Parameters.Add("@SeverityID", SqlDbType.Int).Value = Severity;
                    cmd.Parameters.Add("@CreatedBy", SqlDbType.Int).Value = createdby;
                    cmd.Parameters.Add("@time_millSecond", SqlDbType.NVarChar).Value = time_millisecond;
                    cmd.Parameters.Add("@GroupNo", SqlDbType.Int).Value = ObsAreaId;
                   
                    cmd.CommandTimeout = 0;

                    SqlDataAdapter adp = new SqlDataAdapter(cmd);
                   
                    adp.Fill(Dt);
                   
                }

            }
          
        }
      
        catch(Exception ex)
        {

        }
        if (Dt.Rows.Count > 0)
        {

            return Dt;
        }
        else
        {
            return Dt;
        }
    }


Answers (5)