Pass method parameters through the URL

Asked

Viewed 2,298 times

1

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

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

How to pass method parameters Produto? So they’d 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 it?

1 answer

2

First of all, these parameters are called query string.

You can declare in your method for it to accept requests HTTP GET

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

And change in the archive web config.

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

After that, you can call your webservice thus

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

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

  • is giving this message at the time of compiling. Non recognized webservices configuration section.

  • fix: I cannot publish the webservice, "Unacknowledged webservices configuration section"

  • I removed [Scriptmethod(Usehttpget=true)], leaving only in XML file and it worked

  • I was actually looking at that question, so I’ll edit the answer as soon as I have something more concrete. If any of the answers helped you solve the problem, you can vote positively for it in the little arrows and choose it as correct by marking the sign below the arrows to vote.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.