Can I have an optional parameter for an ASP.NET SOAP web service

If you REALLY have to accomplish this, here’s a sort of hack for the specific case of a web method that has only primitive types as parameters:

[WebMethod]
public void MyMethod(double requiredParam1, int requiredParam2)
{
    // Grab an optional param from the request.
    string optionalParam1 = this.Context.Request["optionalParam1"];

    // Grab another optional param from the request, this time a double.
    double optionalParam2;
    double.TryParse(this.Context.Request["optionalParam2"], out optionalParam2);
    ...
}

Leave a Comment