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

  • SEARCH
  • Home
  • 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 6765077
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T14:40:12+00:00 2026-05-26T14:40:12+00:00

I have created a dummy web service with 2 optional parameters using the .Net

  • 0

I have created a dummy web service with 2 optional parameters using the .Net Webservices, however in the real product we are going to have a lot more optional parameters(think: filters for a query). The problem is that it is not possible to leave out the optional parameters when calling the webservice, meaning there will be a potential dozens of NULL values in every call to the webservice when developing against the real webservice.

Right now this dummy webservice consists of only this, to support 2 optional string parameters:

[WebMethod]
public string HelloWorld(String PARAM_1="", String PARAM_2="")
{   return "";   }

In the WSDL it indeed displays these parameters with minvalue 0 and maxvalue 1:

<s:element minOccurs="0" maxOccurs="1" name="PARAM_1" type="s:string"/>
<s:element minOccurs="0" maxOccurs="1" name="PARAM_2" type="s:string"/>

The problem lies here: When adding this webservice through a web reference in Visual Studio 2010 it will indeed create the service object with the HelloWorld Method. However it does not take into account the optional parameters. It creates a function HelloWorld with no optional parameters. It always requires both PARAM_1 and PARAM_2, so the optional parameters have to be filled with NULLs regardless of which ones we actually would want to use.

The definition VS2010 generates out of the web reference is this, showing the issue:

public string HelloWorld(string PARAM_1, string PARAM_2) {
object[] results = this.Invoke("HelloWorld", new object[] { PARAM_1, PARAM_2});

Is there a way to use webservices with optional parameters in VS2010 without being forced to NULL a potential dozens of optional parameters with every call? We would like to keep using the convenient webreferences in Visual Studio without being forced to do this all the time.

  • 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-26T14:40:12+00:00Added an answer on May 26, 2026 at 2:40 pm

    You can create optional parameters if you wrap all parameters in a separate class. This represents a new message where you can decide on your own to make certain properties optional. You can also provide different constructors in a partial class declaration to the service generated classes.

    This is IMO a better solution than method overloading, which doesn’t even work with web services. You have to create a new and slightly different method for each overload.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have created a custom dialog for Visual Studio Setup Project using the steps
I have created a PHP-script to update a web server that is live inside
I have created a C# class file by using a XSD-file as an input.
I have created a webservice in .net 2.0, C#. I need to log some
I have an ASP.NET page that needs to make calls to multiple web services
I have created a dummy mail to create Empty Label in Google APPs mail.
I am using Cherrypy in a RESTful web service and server returns XML as
I have created a very simple dummy program to understand Delegates and events. In
I create an asp.net 4.0 web application which has a web service for uploading
I have created server with TcpListener, which responds to every request as a dummy

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.