Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions

C# Web Service params string array

Posted on 2006-06-20
Last Modified: 2008-03-21
Hello experts,

I am building a web service in C# which has a large number of input parameters.  Most of them are not necessary except in specific scenarios, but I require users to provide all parameters because thats what the web service needs (for most of them, users just pass a blank string to fulfill the necessary requirements).  

What I would like to know is if it possible to pass FEWER parameters than the method requires (some sort of web service equivalent to Request.QueryParams("value")).  

If I were to be doing this in pure C#, I would just provide a number of method overloads such as:

public void Method1(string a) { }
public void Method1(string a, int b, bool c) { }
public void Method1(string a, int b, bool c, string d) { }

and so forth...

However, this is clearly not just pure C# since each web method needs a unique name and cannot provide overloads.  What I am wondering is if there is some equivalent to Request.QueryParams("value) in a web service so I could pass a variable number of parameters.  This way, I could check if the user provided the given parameter, and act accordingly.  

Is this at all possible?

Question by:TLevin10
  • 5
  • 4
LVL 15

Expert Comment

ID: 16949417
You can overload WebMethods by declaring unique descriptions to each of them...

Take a look here...



publix string TestMe(string g)
     return g;

public string TestMe()
     return TestMe("hello");

Author Comment

ID: 16950538
right, this I already know - this allows overload methods on the server side, but to the client, its 2 different methods (they see "OverLoaded" as the method name for "TestMe(String g)" and "Normal" as the method name for "TestMe()"...

I am trying to find a way to have the client only call one message, but pass different params each time?
LVL 15

Expert Comment

ID: 16950567
Hmm unfortunately I don't have my dev environment here but it can be done....


[WebMethod(Description:="Method 1")]
public string testme(string g)

[WebMethod(Description:="Method 2")]
public string testme()
Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.


Author Comment

ID: 16950639
interesting idea - I will check my dev environment in a little while...

Author Comment

ID: 16951671
It seems that the .NET server will throw an error unless the MessageName is specified for the overloads, which results in the user "seeing" 2 methods...
LVL 15

Expert Comment

ID: 16951691
When you say the user sees 2 methods, is this when they are calling the webservice from inside their application or by browsing to the test web service page?

Author Comment

ID: 16951858
well, either way - when they are browsing the test web service page, they see two methods, and for instance if I set up a form on another page and use that to call the webmethod, I need to rediect them to different locations based on the parameters:

<form action="http://localhost/WebServiceTest/TestServices.asmx/Method1" method="post" target="_blank"> for one set of parameters, and,
<form action="http://localhost/WebServiceTest/TestServices.asmx/Method2" method="post" target="_blank"> for another set of parameters

as an example of when this might fail, is if there is a checkbox which represents a parameter on a web form:

<INPUT type="checkbox" value="True" name="isBoolean"> - This will send a parameter of 'true' for the 'isBoolean' parameter, but...
<INPUT type="checkbox" value="False" name="isBoolean"> - This will send a 'null' parameter to the web method <causing problems>

Really, there should be an overloaded method where the isBoolean property doesn't exist, but for the user to use this method, they would have to call it by a different name:

'http://localhost/WebServiceTest/TestServices.asmx/Method2' instead of

It seems this is an intrinsic business of Web Methods (they need to have unique names): http://www.codeproject.com/soap/RefAndOL.asp

I am hoping that maybe I can find a way around it, but they sure don't make it easy!
LVL 15

Accepted Solution

GavinMannion earned 500 total points
ID: 16951892
The way you are using webservices you cannot do what you are trying to do...

The only way would be to hack it yourself, create a page called MyMethod, let them post to that. Depending on what you get you then forward it to the service and then redirect the response.

Web services also get consumed in code and if you are comsuming the service then the code I posted will create the overload you are looking for.

If you are using asp.net then I don't see why you are posting using forms to the web service... it doesn't really make any sense?

Author Comment

ID: 16953810
Well, I am not the only one using the service - in fact, I'm just the designer of the service - it will be consumed by a series of windows apps and web apps which I have no control over.  Basically, I am trying to make it as easy to reach as possible for those who are going to consume the service.

The only reason I offer the simple ASP.NET examples is that it is easy to see where things can go wrong...

However, I have made the decision to just force users to enter blank parameters if they don't plan on using them - at least this way, the users aren't searching out the correct overload method to call and they just have to pass all the parameters as blanks.  

In such a situation, I don't need the overload methods and since its inherent in WSDL not to allow overloading, I guess this question stands resolved that there is no correct way to overload web methods.

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In an ASP.NET application, I faced some technical problems. In this article, I list them out and show the solutions that I found.  I hope it will be useful. Problem: After closing a pop-up window, the parent page should be refreshed automaticall…
Problem Hi all,    While many today have fast Internet connection, there are many still who do not, or are connecting through devices with a slower connect, so light web pages and fast load times are still popular.    If your ASP.NET page …
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

861 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question