How can I call a ASP .NET web service and pass parameters using the URL?
For example, the URL for the service is like,
http://[localhost]:31856/MySystem/MyAPI.asmx?op=getHeight
I need to pass two parameters a and b, I tried
http://[localhost]:31856/MySystem/MyAPI.asmx?op=getHeight?a=254&b=1
But failed.
Please advice.
Many Thanks,
The question mark immediately following the extension of the template in the URL specifies the beginning point for appending URL parameters. Each URL parameter consists of a parameter name followed by an equal sign, then the value assigned to the parameter.
Query parameters are a defined set of parameters attached to the end of a url. They are extensions of the URL that are used to help define specific content or actions based on the data being passed. To append query params to the end of a URL, a '? ' Is added followed immediately by a query parameter.
URL parameters are made of a key and a value, separated by an equal sign (=). Multiple parameters are each then separated by an ampersand (&).
Go to your report and edit it. Select the desired “API name” of the field in which you want to pass the value of parameter. Select the operator and keep the value box blank/empty, For Ex: the filter of AccountID as shown in below image.
If you need to pass more than one parameter, use this format param1=value1¶m2=value2
and so on.So your link should be:
http://[localhost]:31856/MySystem/MyAPI.asmx/AnyMethodName?op=getHeight&a=254&b=1
You need a method like this.This method returns a list of strings,its just for demonstration.
[WebMethod]
public List<string> AnyMethodName(string op, string a, string b)
{
//Do whatever you want, get answer
return (ans.ToList());
}
I had the same problem and I needed to add the following in my webconfig inside the system.web -tag:
<webServices>
<protocols>
<add name="HttpGet" />
</protocols>
</webServices>
The rest was pretty much like already mentioned (using the example from Ashwin's answer, just removed the op-parameter)
[WebMethod]
public List<string> AnyMethodName(string a, string b)
{
//Do whatever you want, get answer
return (ans.ToList());
}
After that I was able to call the webservice with the following (removed the op-parameter again):
http://localhost/MySystem/MyAPI.asmx/AnyMethodName?a=254&b=1
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With