Pass parameters to the method by URL

1

How do I capture parameters requested by the URL in a webservice ?

For example: I have the following webservice: http://localhost/teste/WebService1.asmx/Produto

How do I pass the parameters of the Produto method? To make them look something like this:

http://localhost/teste/WebService1.asmx/Produto?a=sincroniza&dado=produto&id_vendedor=2666&id_grupo=1700&id_usuario=2925&id_empresa=2004

And how would I read this?

    
asked by anonymous 26.10.2015 / 02:18

1 answer

2

First of all, these parameters are called query string .

You can declare in your method to accept HTTP GET requests

[WebMethod]
[ScriptMethod(UseHttpGet=true)]
public string ConverterNumero(int param){ 
    ... 
}

And change in web.config

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

Then you can call your webservice this way

http://site.com/Servico.asmx/ConverterNumero?param=1

And your ConverterNumero method will be called with the value of param being 1 .

    
26.10.2015 / 11:19