Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I call a web service and pass parameters using the URL

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,

like image 360
DafaDil Avatar asked Jun 25 '12 12:06

DafaDil


People also ask

How do I pass parameters to URL?

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.

How do you give a URL a query?

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.

How do I pass multiple path parameters in URL?

URL parameters are made of a key and a value, separated by an equal sign (=). Multiple parameters are each then separated by an ampersand (&).

How do I pass parameters in URL in Salesforce?

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.


2 Answers

If you need to pass more than one parameter, use this format param1=value1&param2=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());
    }
like image 85
Ashwin Singh Avatar answered Sep 23 '22 17:09

Ashwin Singh


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
like image 23
punatiainen Avatar answered Sep 22 '22 17:09

punatiainen