Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p><code>params</code> is just syntactic sugar, why not just do something like this:</p> <pre><code>var myWebService = new MyWebService(); myWebService.MyMethod(new string[] { "one", "two", "three" }); </code></pre> <p>The method signature on the web service side would just be:</p> <pre><code>public void MyMethod(string[] values); </code></pre> <p>If you post your web method maybe I can provide a better answer.</p> <p><strong>EDIT</strong><br /> If you can't modify the web method signature, then I would use an <a href="http://msdn.microsoft.com/en-us/library/bb383977.aspx" rel="nofollow">extension method</a> to wrap the difficult to call web service. For example, if our web service proxy class looks like:</p> <pre><code>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; } } </code></pre> <p>Then you could create an extension method that accepts the string array as <code>params</code> and makes the call to <code>MyWebService</code>.</p> <pre><code>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 &gt; 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]); } } </code></pre> <p>You could then call your web service using the extension method you created (just be sure to add a <code>using</code> statment for the namespace where you declared you extension method):</p> <pre><code>var svc = new MyWebService(); svc.MyMethod("this", "is", "a", "test"); </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload