Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4599052
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T23:29:09+00:00 2026-05-21T23:29:09+00:00

I would like to pass some parameters to a web method as an array.

  • 0

I would like to pass some parameters to a web method as an array. The web method’s signature does not have the params keyword.

I have a variable number of parameters (as the web method accepts) so I cannot put the array into n single variables.

How can this be done?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-21T23:29:10+00:00Added an answer on May 21, 2026 at 11:29 pm

    params is just syntactic sugar, why not just do something like this:

    var myWebService = new MyWebService();
    myWebService.MyMethod(new string[] { "one", "two", "three" });
    

    The method signature on the web service side would just be:

    public void MyMethod(string[] values);
    

    If you post your web method maybe I can provide a better answer.

    EDIT
    If you can’t modify the web method signature, then I would use an extension method to wrap the difficult to call web service. For example, if our web service proxy class looks like:

    public class MyWebService
    {
        public bool MyMethod(string a1, string a2, string a3, string a4, string a5,
            string a6, string a7, string a8, string a9, string a10)
        {
            //Do something
            return false;
        }
    }
    

    Then you could create an extension method that accepts the string array as params and makes the call to MyWebService.

    public static class MyExtensionMethods
    {
        public static bool MyMethod(this MyWebService svc, params string[] a)
        {
            //The code below assumes you can pass in null if the parameter
            //is not specified. If you have to pass in string.Empty or something
            //similar then initialize all elements in the p array before doing
            //the CopyTo
            if(a.Length > 10) 
                throw new ArgumentException("Cannot pass more than 10 parameters.");
    
            var p = new string[10];
            a.CopyTo(p, 0);
            return svc.MyMethod(p[0], p[1], p[2], p[3], p[4], p[5], 
                                p[6], p[7], p[8], p[9]);
        }
    }
    

    You could then call your web service using the extension method you created (just be sure to add a using statment for the namespace where you declared you extension method):

    var svc = new MyWebService();
    svc.MyMethod("this", "is", "a", "test");
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I would like to have a function that modifies some variable list of parameters
I would like to pass some attributes to actionListener method. My implementation is like...
I have a * -parameter method. I would like to be able to pass
I would like to pass some parameters to a customized Linux init via the
Would like to pass some parameters to the _path for link_to or redirect_to. For
I would like to create some sort of function where you pass in a
I have a form that has label values that I would like to pass
How would i pass some parameters to a new thread that runs a function
I have a stored procedure that I would like to pass a string to,
I am creating some web services which I would like to secure using a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.