How to have optional variables in an ASP.Net WebService

May 10, 2012

I searched around and couldn’t find anything specific to fit my needs. I need to be able to have the same call, yet have the ability for optional variables to be posted as well. The problem is you can’t have optional variables in a webservice. That’s not exactly true, you still have access to the same request variable that gets the information and parses it so why not use it.

In any one of your WebMethod functions simply use HttpContext.Current.Request to grab those extra variables.

For example, I needed some way of seeing if the path variable is being supplied, here’s how I did that:

Dim path As String = ""

path = HttpContext.Current.Request("path")

I hope this helps someone out, if so please let me know via a +1, comment, or link back to my blog.

+1 this post if it helped you!

Leave a Reply