Passing Parameters to .NET Web Service as a Query String (GET Method) or POST Request

First of all the way of passing parameters must be defined in web.config as follows:

<system.web>
<webServices>
<protocols>
<add name="HttpGet"/>
<add name="HttpPost"/>
</protocols>
</webServices>
</system.web>


Then the URL of the web service may include parameters as query string.
http://tempuri.org/webservice.asmx/MethodCaseSensitive?parameter1=yes&parameter2=123

MethodCaseSensitive is the name of web method to be performed as part of the webservice called webservice.asmx.


In case you need POST method of sending parameters just use a form and text fields as in the following example:


<form name="input" action="http://tempuri.org/webservice.asmx/MethodCaseSensitive" method="post">
<input name="parameter1" type="text">
<input name="parameter2" type="text">
<input value="Submit" type="submit">
</form>

Both of methods return XML response as it is defined in the web method.

The Web Service results can be easily checked using the .NET ability for integrated passing of parametersin a web interface:
http://tempuri.org/webservice.asmx?op=MethodCaseSensitive

The screen allows the user to enter web service parameters and submit them. The result is the same.

No comments:

Post a Comment