Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Possible to invoke ASMX service with parameter via url query string?

Tags:

asmx

I've got a asmx service that takes a single int parameter. I can open the URL to the service and see the service description screen. From here I can enter the query parameters into a form and invoke the web service.

Is there any way to invoke a web service directly from a URL/query string?

This doesnt work:

http://localhost:4653/MyService.asmx?op=MyWebMethod&intParameter=1

Any ideas? I'd really like to be able to do this from a standard link due to some deployment issues. Am I going to have to wrap the request in a normal aspx page?

like image 471
Alex Avatar asked Jan 05 '10 15:01

Alex


People also ask

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

Step 1: Click on Add Service Reference and add reference of service . It creates reference in a partial class to the service and all the methods which you need to call the service under the project namespace. Step 2: Add the same class in using ..

How do I add parameters to a URL 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.

Does Asmx use soap?

ASMX provides the ability to build web services that send messages using the Simple Object Access Protocol (SOAP). SOAP is a platform-independent and language-independent protocol for building and accessing web services.


2 Answers

You can decorate your method to allow HTTP GET requests, which should in turn do what you're looking for like so:

[WebMethod]   [ScriptMethod(UseHttpGet=true)] public string MyNiftyMethod(int myint) {     // ... code here } 

And edit the web.config :

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

Then you'll be able to call this method like so:

http://mysite.com/Service.asmx/MyNiftyMethod?myint=12345

EDIT: Note that this method of performing GET requests does come with some security risks. According to the MSDN documentation for UseHttpGet:

Setting the UseHttpGet property to true might pose a security risk for your application if you are working with sensitive data or transactions. In GET requests, the message is encoded by the browser into the URL and is therefore an easier target for tampering.

like image 120
Scott Anderson Avatar answered Sep 21 '22 03:09

Scott Anderson


ASMX web services use SOAP. SOAP requests use only POST to invoke methods. You will need to generate a proxy client in your aspx page to invoke the web service. If you really need to use GET verbs to invoke web services you might need to use a different approach such as WCF REST.

like image 33
Darin Dimitrov Avatar answered Sep 21 '22 03:09

Darin Dimitrov