locked
How to accept JSON array in ASMX  webservice RRS feed

  • Question

  • User1804579801 posted

    my requriement in a mobile app is  I will select multiple trainees and click on "Mark Attendance" button  bypassing these traineeids to  asmx webservice and update in the SQL SERVER Database 

    my webservice method 

    [WebMethod(EnableSession = false)]
     [ScriptMethod(UseHttpGet = true, ResponseFormat = ResponseFormat.Json)]//Specify return format.
      public void markattendence(int iTrainingId, List<TraineeDetails> iParticipantId)
      {
         TraineeDetails d1 = new TraineeDetails();
         DataTable dt = new DataTable();
         using (SqlConnection con = new SqlConnection(strConn))
         {
             SqlCommand cmd = new SqlCommand("App_Service", con);
             try
             {
                 foreach (var item in iParticipantId)
                 {
                 cmd.CommandType = CommandType.StoredProcedure;
                 cmd.Parameters.AddWithValue("@Paravalue", "13");
                 cmd.Parameters.AddWithValue("@value", iTrainingId.ToString());
                 cmd.Parameters.AddWithValue("@value1", iParticipantId.ToString());
                 cmd.Parameters.AddWithValue("@value2", "0");
                 cmd.Parameters.AddWithValue("@value3", "0");
                 }
                 con.Open();
                 cmd.ExecuteNonQuery();
                 SqlDataAdapter da = new SqlDataAdapter(cmd);
                 da.Fill(dt);
    
                 d1.status = 0;
                 d1.message = "success";
                 d1.data = new List<TraineeDetalis1>();
                 for (int i = 0; i < dt.DefaultView.Count; i++)
                 {
                     d1.data.Add(new TraineeDetalis1 { vProfile_image = dt.Rows[i]["vProfile_image"].ToString(), iParticipantId =int.Parse(dt.Rows[i]["iParticipantId"].ToString()), vPhonenumber = dt.Rows[i]["vPhonenumber"].ToString(), vName = dt.Rows[i]["vName"].ToString() });
                 }
                 this.Context.Response.ContentType = "application/json; charset=utf-8";
                 JavaScriptSerializer js = new JavaScriptSerializer() { MaxJsonLength = 867530900 };
                 string JSONResult = js.Serialize(d1);
                 string FinalJsonstring1 = JSONResult.Replace("[", "");
                 string FinalJsonstring2 = FinalJsonstring1.Replace("]", "");
                 Context.Response.Write(FinalJsonstring2);
                 //Context.Response.Write(JSONResult);
                 cmd.Dispose();
                 con.Close();
                 con.Dispose();
             }
             catch (Exception ex)
             {
                 ExceptionLogging.SendErrorToText(ex);
                 status = ex.GetHashCode().ToString();
                 message = ex.Message.ToString();
                 throw new SoapException(ex.Message, SoapException.ServerFaultCode, Context.Request.Url.AbsoluteUri);
             }
             finally
             {
                 cmd.Dispose();
                 con.Close();
                 con.Dispose();
             }
         }
     }
    

    Iam getting below error in the mobile app when I inspect in the network  . Please suggest checked in google but did not solve my requriement 

    System.InvalidOperationException: markattendence Web Service method name is not valid.
       at System.Web.Services.Protocols.HttpServerProtocol.Initialize()
       at System.Web.Services.Protocols.ServerProtocolFactory.Create(Type type, HttpContext context, HttpRequest request, HttpResponse response, Boolean& abortProcessing)

    Monday, December 2, 2019 11:11 AM

All replies

  • User1804579801 posted

    tried below code

    [WebMethod(EnableSession = false)]
     [ScriptMethod(UseHttpGet = true, ResponseFormat = ResponseFormat.Json)]//Specify return format.
      public void markattendence(int iTrainingId, string [] iParticipantId)
      {
         TraineeDetails d1 = new TraineeDetails();
         DataTable dt = new DataTable();
         using (SqlConnection con = new SqlConnection(strConn))
         {
             SqlCommand cmd = new SqlCommand("App_Service", con);
             try
             {
                 if (iParticipantId != null)
                 {
                     foreach (var item in iParticipantId)
                     {
                         cmd.CommandType = CommandType.StoredProcedure;
                         cmd.Parameters.AddWithValue("@Paravalue", "13");
                         cmd.Parameters.AddWithValue("@value",iTrainingId.ToString());
                         cmd.Parameters.AddWithValue("@value1",item.ToString());
                         cmd.Parameters.AddWithValue("@value2", "0");
                         cmd.Parameters.AddWithValue("@value3", "0");
                     }
                 }
                 con.Open();
                 cmd.ExecuteNonQuery();
                 SqlDataAdapter da = new SqlDataAdapter(cmd);
                 da.Fill(dt);
    
                 d1.status = 0;
                 d1.message = "success";
                 d1.data = new List<TraineeDetalis1>();
                 for (int i = 0; i < dt.DefaultView.Count; i++)
                 {
                     d1.data.Add(new TraineeDetalis1 { vProfile_image = dt.Rows[i]["vProfile_image"].ToString(), iParticipantId =int.Parse(dt.Rows[i]["iParticipantId"].ToString()), vPhonenumber = dt.Rows[i]["vPhonenumber"].ToString(), vName = dt.Rows[i]["vName"].ToString() });
                 }
                 this.Context.Response.ContentType = "application/json; charset=utf-8";
                 JavaScriptSerializer js = new JavaScriptSerializer() { MaxJsonLength = 867530900 };
                 string JSONResult = js.Serialize(d1);
                 string FinalJsonstring1 = JSONResult.Replace("[", "");
                 string FinalJsonstring2 = FinalJsonstring1.Replace("]", "");
                 Context.Response.Write(FinalJsonstring2);
                 Context.Response.Write(JSONResult);
                 //return FinalJsonstring2;
                 cmd.Dispose();
                 con.Close();
                 con.Dispose();
             }
             catch (Exception ex)
             {
                 ExceptionLogging.SendErrorToText(ex);
                 status = ex.GetHashCode().ToString();
                 message = ex.Message.ToString();
                 throw new SoapException(ex.Message, SoapException.ServerFaultCode, Context.Request.Url.AbsoluteUri);
             }
             finally
             {
                 cmd.Dispose();
                 con.Close();
                 con.Dispose();
             }
         }
     }
    

    but iam getting below error in jquery when i see inspect and see the network . Please suggest how to proceed 

    System.Web.Services.Protocols.SoapException: Conversion failed when converting the varchar value &#39;[{&quot;iParticipantId&quot;:&quot;244&quot;},{&quot;iParticipantId&quot;:&quot;246&quot;}]&#39; to data type int.
       at WebService.markattendence(Int32 iTrainingId, String[] iParticipantId) in e:\E Drive\Pavani\Projects_2018\TrainingTeamTrackingTool\App_Code\WebService.cs:line 845
    Monday, December 2, 2019 12:28 PM
  • User475983607 posted

    The main issue is not following standard and openly punished web service programming patterns.  You specified the return type as JSON in the script method attribute but the method signature returns void.   Web Methods should return the actual type List<TraineeDetalis1>.

    public List<TraineeDetalis1>( markattendence(int iTrainingId, List<TraineeDetails> iParticipantId)
    {

    The framework will serialize the type.   You'll need to fix your code to populate and return a strong type.

    Monday, December 2, 2019 12:28 PM
  • User1804579801 posted

    The modified method as below 

     [WebMethod(EnableSession = false)]
     [ScriptMethod(UseHttpGet = true, ResponseFormat = ResponseFormat.Json)]//Specify return format.
      public List<TraineeDetalis1> markattendence(int iTrainingId, List<TraineeDetails> iParticipantId)
      {
        TraineeDetails d1 = new TraineeDetails();
         DataTable dt = new DataTable();
         using (SqlConnection con = new SqlConnection(strConn))
         {
             SqlCommand cmd = new SqlCommand("App_Service", con);
             try
             {
                 if (iParticipantId != null)
                 {
                     foreach (var item in iParticipantId)
                     {
                         cmd.CommandType = CommandType.StoredProcedure;
                         cmd.Parameters.AddWithValue("@Paravalue", "13");
                         cmd.Parameters.AddWithValue("@value",iTrainingId.ToString());
                         cmd.Parameters.AddWithValue("@value1",item.ToString());
                         cmd.Parameters.AddWithValue("@value2", "0");
                         cmd.Parameters.AddWithValue("@value3", "0");
                     }
                 }
                 con.Open();
                 cmd.ExecuteNonQuery();
                 SqlDataAdapter da = new SqlDataAdapter(cmd);
                 da.Fill(dt);
                 d1.status = 0;
                 d1.message = "success";
                 d1.data = new List<TraineeDetalis1>();
                 for (int i = 0; i < dt.DefaultView.Count; i++)
                 {
                     d1.data.Add(new TraineeDetalis1 { vProfile_image = dt.Rows[i]["vProfile_image"].ToString(), iParticipantId =int.Parse(dt.Rows[i]["iParticipantId"].ToString()), vPhonenumber = dt.Rows[i]["vPhonenumber"].ToString(), vName = dt.Rows[i]["vName"].ToString() });
                 }
                 //this.Context.Response.ContentType = "application/json; charset=utf-8";
                 JavaScriptSerializer js = new JavaScriptSerializer() { MaxJsonLength = 867530900 };
                 string JSONResult = js.Serialize(d1);
                 string FinalJsonstring1 = JSONResult.Replace("[", "");
                 string FinalJsonstring2 = FinalJsonstring1.Replace("]", "");
                 Context.Response.Write(FinalJsonstring2);
                 //Context.Response.Write(JSONResult);
                 return d1.data;
               
             }
             catch (Exception ex)
             {
                 ExceptionLogging.SendErrorToText(ex);
                 status = ex.GetHashCode().ToString();
                 message = ex.Message.ToString();
                 throw new SoapException(ex.Message, SoapException.ServerFaultCode, Context.Request.Url.AbsoluteUri);
             }
             finally
             {
                 cmd.Dispose();
                 con.Close();
                 con.Dispose();
             }
         }
     }

    Iam getting the below from ajax jquery method 

    1. iParticipantId: "[{"iParticipantId":"247"},{"iParticipantId":"248"}]"  which is an arrary 
    2. iTrainingId: "45"

    My jquery method 

    var dataSending = {
    "iTrainingId":$("#itrainid_for_current_program").val(),
    "iParticipantId": JSON.stringify(ipart),
    "session_date": $("#itrainid_date_current_program").val()
    }

    var sendMarkAttendance = function(userDetails) {
    SpinnerPlugin.activityStart("Loading...", { dimBackground: true });
    $.ajax({
    type: "POST",
    url: base_url + "markattendence",
    data: userDetails,
    timeout: 60000,
    dataType: "json",
    headers: {
    "X-Api-Key": localStorage.getItem("auth_key"),
    },
    Complete: function(xhr) {
    xhr.getResponseHeader("Accept", "json");
    },
    success: function(res) {
    var html = "";
    if (res.status == 0) {
    getCurrentRunningBatch();
    } else {
    SpinnerPlugin.activityStop();
    }
    },
    error: function(xhr, status, err) {
    ErrorHandler(xhr, status, err);
    }
    });
    }

    Iam still getting below error. Please suggest  

    System.InvalidOperationException: markattendence Web Service method name is not valid.
       at System.Web.Services.Protocols.HttpServerProtocol.Initialize()
       at System.Web.Services.Protocols.ServerProtocolFactory.Create(Type type, HttpContext context, HttpRequest request, HttpResponse response, Boolean& abortProcessing)
    Tuesday, December 3, 2019 6:02 AM
  • User475983607 posted

    There are too many basic problems with the code shown to provide accurate assistance.   

    The main problem is you've defined the markattendance() web method as a GET but your AJAX is sending a POST. 

    IMHO, You need to pay more attention to the details, testing, and debugging.  Perhaps build a simple test that only test sending inputs. 

    public string markattendence(int iTrainingId, List<TraineeDetails> iParticipantId)
    {
       return "Hello World";
    }

    Once you get the POST working then add a response type and test the AJAX code.  Next, add the logic and test.

    Tuesday, December 3, 2019 11:39 AM
  • User288213138 posted

    Hi nagapavanich,

    How to accept JSON array in ASMX  webservice

    [ScriptMethod(UseHttpGet = true, ResponseFormat = ResponseFormat.Json)]

    According to your description, do you want to get the JSON array in jquery from the web service?

    If this is your requirement, you can refer to below code.

     <script type="text/javascript">
            $(function () {
                $("#Button1").click(function () {
                    var arr = [
                        { Id: 1, FirstName: "FN", LastName: "LN", Gender: "M", Salary: "S" }
                    ];
                    $.ajax({
                        type: 'GET',
                        url: 'EmployeeService.asmx/GetData',
                        contentType: 'application/json; charset=utf-8',
                        dataType: 'Json',
                        data: "employees=" + JSON.stringify(arr),
                        success: function (d) {
                            console.log(d.data);
                        }
                    });
                });
            })
        </script>
    <input id="Button1" type="button" value="button" />
    
    [WebMethod(EnableSession = false)]
    [ScriptMethod(UseHttpGet = true, ResponseFormat = ResponseFormat.Json)]
    public void GetData(List<Employee> employees)
            {            
                JavaScriptSerializer js = new JavaScriptSerializer() { MaxJsonLength = 867530900 };
                string JSONResult = js.Serialize(employees);
                string FinalJsonstring1 = JSONResult.Replace("[", "");
                string FinalJsonstring2 = FinalJsonstring1.Replace("]", "");
                Context.Response.Write(FinalJsonstring2);
            }

    The result:

    I tried to reproduce your problem according to your code, but there are some problems in your ajax. So I wrote a demo based on your requirement.

    Best regards,

    Sam

    Wednesday, December 4, 2019 6:34 AM
  • User1804579801 posted

    Please find below a sample code every time it goes to error "There was an error retrieving records". I have checked by consuming webservice on an aspx page.Please suggest 

    below Webservice code:
      I do not want to return a list I only want List as a parameter so that can take the participants and insert into my SQL SERVER 2005 database

     [WebMethod(EnableSession = false)]
      [ScriptMethod(UseHttpGet = false, ResponseFormat = ResponseFormat.Json)]//Specify return format.
      public void markattendence(int iTrainingId, List<TraineeDetalis1> iParticipantId)
      {
          TraineeDetails d1 = new TraineeDetails();
          DataTable dt = new DataTable();
          using (SqlConnection con = new SqlConnection(strConn))
          {
              SqlCommand cmd = new SqlCommand("App_Service", con);
              cmd.CommandType = CommandType.StoredProcedure;
              try
              {
                  string pid = string.Empty;
                  if (iParticipantId != null)
                  {
                      pid = String.Join(",", from item in iParticipantId select item.iParticipantId);
                  }
                  cmd.Parameters.AddWithValue("@Paravalue", "13");
                  cmd.Parameters.AddWithValue("@Value", iTrainingId.ToString());
                  cmd.Parameters.AddWithValue("@Value1", pid);
                  cmd.Parameters.AddWithValue("@Value2", "0");
                  cmd.Parameters.AddWithValue("@Value3", "0");
                  con.Open();
                  cmd.ExecuteNonQuery();
                  JavaScriptSerializer js = new JavaScriptSerializer() { MaxJsonLength = 867530900 };
                  string JSONResult = js.Serialize(iParticipantId);
                  // string FinalJsonstring1 = JSONResult.Replace("[", "");
                  // string FinalJsonstring2 = FinalJsonstring1.Replace("]", "");
                  Context.Response.Write(JSONResult);
                  SqlDataAdapter da = new SqlDataAdapter(cmd);
                  da.Fill(dt);
                  d1.status = 0;
                  d1.message = "success";
                  d1.data = new List<TraineeDetalis1>();
                  for (int i = 0; i < dt.DefaultView.Count; i++)
                  {
                      d1.data.Add(new TraineeDetalis1 { vProfile_image = dt.Rows[i]["vProfile_image"].ToString(), iParticipantId = int.Parse(dt.Rows[i]["iParticipantId"].ToString()), vPhonenumber = dt.Rows[i]["vPhonenumber"].ToString(), vName = dt.Rows[i]["vName"].ToString() });
                  }
                  cmd.Dispose();
                  con.Close();
                  con.Dispose();
              }
              catch (Exception ex)
              {
                  ExceptionLogging.SendErrorToText(ex);
                  status = ex.GetHashCode().ToString();
                  message = ex.Message.ToString();
                  throw new SoapException(ex.Message, SoapException.ServerFaultCode, Context.Request.Url.AbsoluteUri);
              }
              finally
              {
                  cmd.Dispose();
                  con.Close();
                  con.Dispose();
              }
          }
      }

    My aspx page 

    <%@ Page Language="C#" AutoEventWireup="true" CodeFile="appcheck.aspx.cs" Inherits="appcheck" %>
    
    <!DOCTYPE html>
    
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head runat="server">
        <title></title>
            <script src="js/jquery-1.10.2.min.js"></script>
         <script type="text/javascript">
             var dataSending = {
                 "iTrainingId": 45,
                 "iParticipantId": [{ "iParticipantId": "254" }, { "iParticipantId": "255" }]
                 
             }
             $(document).ready(function () {
                 $.ajax({
                     type: "POST",
                     url: "Webservice.asmx/markattendence",
                     contentType: "application/json; charset=utf-8",
                     dataType: "json",
                     data: JSON.stringify(dataSending),
                     success: function (res) {
                         alert(res.data);
                     },
                     error: function (e) {
                         $("#Something").html("There was an error retrieving records");
                     }
                 });
             });
        </script>
      
    
    </head>
    <body>
        <form id="form1" runat="server">
           <div id="Something">
            </div>
        </form>
    </body>
    </html>
    

    Thursday, December 5, 2019 11:17 AM
  • User475983607 posted

    It seems the original issue has been fixed and this is a new issue.   

    Share the actual error message and all the relevant code which induces the stored procedure.  I assume you have bugs in the stored procedure or design which we cannot see.

    Please find below a sample code every time it goes to error "There was an error retrieving records". I have checked by consuming webservice on an aspx page.Please suggest 

    I suggest basic testing and troubleshooting rather than posting incomplete source.  Test the stored procedure using SSMS to make sure the stored procedure works as expected.  Next test the web method.  Debugging is a fundamental concept in programming and you should be able to perform basic troubleshooting steps.

    Thursday, December 5, 2019 11:43 AM
  • User1804579801 posted

    I have done the below before posting into forum 

    I have checked my aspx page before posting into forms and my requriement was participants' attendance should be inserted into the SQL server and it was inserted successfully. from my aspx page. But when I call the same webservice in the mobile app ajax jquery method which I Posted earlier  I get the below error  "Web Service method name is not valid" 

    Declare  @ProjectTypeId int, @count int,@Value varchar(150),@Value1 varchar(MAX),@TrainerId int 
    select @ProjectTypeId=ProjectTypeId ,@TrainerId=TrainerId  from Table_Batch_DetailsInfo where BatchId=@Value 
    
    if(@ProjectTypeId=1)--Corporate--
    begin
    --table variables--
     DECLARE @ParticiPant_Data TABLE (
        Participant_Id int
    );
    insert into  @ParticiPant_Data
    select * from splitToInt(@Value1,',') --converting comma separated string to integer and inserting into table variables 
    
    
    select @count=COUNT(Trainee_atten_logId) from  Table_Trainee_Attendance_Info where 
    TraineeId in(select Participant_Id from @ParticiPant_Data) and BatchId=@Value and 
    CONVERT(varchar(50),AttendanceDate,103)=CONVERT(varchar(50),GETDATE(),103)
    
    
    select  Corporation_Trainee_Id  as iParticipantId,Name as vName,Mobile as vPhonenumber,'' as vProfile_image 
    from Table_Trainee_Corporate_Info where BatchId=@Value 
    
    
    if(@count=0)
    begin
    
    insert into  Table_Trainee_Attendance_Info(BatchId,Attendance,AttendanceDate,SessionType,TrainerId,TraineeId)
    select 45,'Present',GETDATE(),'Session1',1,  Participant_Id from @ParticiPant_Data
    end
    end

    My Requriement is to insert data into a database but every time Iam getting  below error so tried just to check below 

    System.InvalidOperationException: markattendence Web Service method name is not valid.
       at System.Web.Services.Protocols.HttpServerProtocol.Initialize()
       at System.Web.Services.Protocols.ServerProtocolFactory.Create(Type type, HttpContext context, HttpRequest request, HttpResponse response, Boolean& abortProcessing)

    Another Trial JUST to CHECK

    I also checked with a normal web method like below just to test this is just to test so I have used only Get 

     [WebMethod(EnableSession = false)]
      [ScriptMethod(UseHttpGet = true, ResponseFormat = ResponseFormat.Json)]//Specify return format.
      public void markattendence(int iTrainingId, List<TraineeDetalis1> iParticipantId)
      {
          JavaScriptSerializer js = new JavaScriptSerializer() { MaxJsonLength = 867530900 };
          string JSONResult = js.Serialize(iParticipantId);
          string FinalJsonstring1 = JSONResult.Replace("[", "");
          string FinalJsonstring2 = FinalJsonstring1.Replace("]", "");
          Context.Response.Write(FinalJsonstring2);
      }

    aspx consuming 

      <script src="js/jquery-1.10.2.min.js"></script>
         <script type="text/javascript">
             var dataSending = {
                 "iTrainingId": 45,
                 "iParticipantId": [{ "iParticipantId": "254" }, { "iParticipantId": "255" }]
                 
             }
             $(document).ready(function () {
                 $.ajax({
                     type: "GET",
                     url: "Webservice.asmx/markattendence",
                     contentType: "application/json; charset=utf-8",
                     dataType: "json",
                     data: "json=" + JSON.stringify(dataSending),
                     success: function (d) {
                         alert(d.data);
                     },
                     error: function (e) {
                         $("#Something").html("There was an error retrieving records");
                     }
                 });
             });
        </script>
           

    but iam getting error invalid web service call missing value iTrainingId but iam passing iTraniningId. Please Suggest 

    Thursday, December 5, 2019 12:28 PM
  • User475983607 posted

    Your response is very confusing.  The biggest issue I see that you are facing is a lack of debugging and troubleshoot experience plus you are not following openly published standards.

    I assume the original error, Web Service method name is not valid,  has been solved by making sure the AJAX method matches the web method by both being a POST.   Now, it seems you have 2 new issues after fixing the first.

    • There was an error retrieving records
    • Missing value iTrainingId but iam passing iTraniningId

    I cannot solve all the problems with your code, and there are many issues, because you did not include all the relevant code.  However, I can help you with basic troubleshooting steps.  The following code illustrates how to troubleshoot web method input errors.  The code also highlights standard service programming patterns.  I took the liberty to clean up the spelling errors and updated the code to use standard naming conventions.

    Service and model

        /// <summary>
        /// Summary description for WebService1
        /// </summary>
        [WebService(Namespace = "http://tempuri.org/")]
        [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
        [System.ComponentModel.ToolboxItem(false)]
        // To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the following line. 
        [System.Web.Script.Services.ScriptService]
        public class WebService1 : System.Web.Services.WebService
        {
            [Serializable]
            public class TraineeDetails
            {
                public int TrainingId { get; set; }
                public int[] ParticipantId { get; set; }
            }
    
            [WebMethod]
            public TraineeDetails MarkAttendence(TraineeDetails Details)
            {
                return Details;
            }
    

    AJAX

    <!DOCTYPE html>
    
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head runat="server">
        <title></title>
    
    </head>
    <body>
        <form id="form1" runat="server">
            <asp:LinkButton ID="LinkButton1" runat="server">LinkButton</asp:LinkButton>
        </form>
        <div id="result">
        </div>
        <script src="https://code.jquery.com/jquery-1.12.4.js"></script>
        <script>
    
            $("#<%= LinkButton1.ClientID%>").click(function (e) {
                e.preventDefault();
                var data = {
                    "Details":
                    {
                        "TrainingId": 1,
                        "ParticipantId": [254, 255]
                    }
                }
                $.ajax({
                    type: "POST",
                    url: '/WebService1.asmx/MarkAttendence',
                    data: JSON.stringify(data),
                    dataType: 'json',
                    contentType: "application/json; charset=utf-8",
                }).done(function (data) {
                    console.log(data);
                });
            });
        </script>
    </body>
    </html>

    Response

    {
        "d": {
            "__type": "WebFormsDemo.WebService1+TraineeDetails",
            "TrainingId": 1,
            "ParticipantId": [
                254,
                255
            ]
        }
    }

    Once you get the basic IO working you can move on to debugging the stored procedure and ADO.NET logic.

    Thursday, December 5, 2019 2:59 PM
  • User1378345757 posted

    I created an asmx page in vs 2019. I copied the code from mgebhart. Thank you mgebhart

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Web;
    using System.Web.Services;
    
    namespace WebApplication6
    {
        /// <summary>
        /// Summary description for WebService1
        /// </summary>
        [WebService(Namespace = "http://tempuri.org/")]
        [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
        [System.ComponentModel.ToolboxItem(false)]
        // To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the following line. 
         [System.Web.Script.Services.ScriptService]
    
        //gekopieerd van https://forums.asp.net/t/2162075.aspx?How+to+accept+JSON+array+in+ASMX+webservice
    
        public class WebService1 : System.Web.Services.WebService
        {
            [Serializable]
            public class TraineeDetails
            {
                public int TrainingId { get; set; }
                public int[] ParticipantId { get; set; }
            }
            [WebMethod]
            public TraineeDetails MarkAttendence(TraineeDetails Details)
            {
                return Details;
            }
    
            [WebMethod]
            public string HelloWorld()
            {
                return "Hello World";
            }
        }
    }

    then I switched to postman for posting a request.

    In the header the address

    https://localhost:44347/WebService1.asmx/MarkAttendence

    in the body 

     {
                    "Details":
                    {
                        "TrainingId": 1,
                        "ParticipantId": [254, 255]
                    }}

    and in the header I inserted the Content-type as application/json

    pressing the send button showed

    {
        "d": {
            "__type": "WebApplication6.WebService1+TraineeDetails",
            "TrainingId": 1,
            "ParticipantId": [
                254,
                255
            ]
        }
    }

    debug in vs2019

    I can not insert a picture of the debug window in vs 2019 but it showed when hoovering "return Details" the items in my json request

    Friday, January 22, 2021 10:12 AM
  • User-442109440 posted

    Wao got the answer thank you all. https://gamesapkworld.com/sky-fighter-mod-apk/i was looking and searching it for very long time.

    Friday, January 22, 2021 2:23 PM