Change the "Web Reference URL" of the Webservice added by add web

Asked

Viewed 161 times

-1

I wonder if it would be possible and how to make this change by taking the web address.config inserir a descrição da imagem aqui

  • What change ?

  • @Pedro, I added an image to make it easier to understand

  • It wasn’t clear. What you specifically need ?

  • @Pedro, did you see the image? When you add a webservice with the add web add option, it already adds the path in Properties, I want to take the path of the web.config

  • You need to create an instance of your Webreference class. Next you should use the Url property.

  • @Peter, when you have time, could post a practical example as an answer to this question, thank you

  • posted an example. see if it’s useful for what you need.

Show 2 more comments

2 answers

1


Web.config

Inside the tag add your new url to the Web Reference.

<appSettings>
    <add key="urlWebService" value="http://www.google.com" />
</appSettings>

When you instantiate the proxy class of your Web Service, change the URL to the url registered on the web.config:

using (var webService = new Foo.WebService())
{
    webService.Url = ConfigurationManager.AppSettings["urlWebService"];
}

Don’t forget that the names I used (google site, Foo.Webservice) are fictitious names, because I don’t know the name of your project’s templates.

  • perfect answer, thank you so much for having devoted time in response.

  • Nothing, I’m glad it worked! Thank you very much.

0

You need to create an instance of the class you want to use generated by the Webreference proxy classes. Let me give you an example using the Post Office Webservice.

Can be accessed using the link below: http://ws.correios.com.br/calculador/CalcPrecoPrazo.asmx

After adding the reference of your Webservice, please enter the class and refer to the Url property.

 br.com.correios.ws.CalcPrecoPrazoWS client = new br.com.correios.ws.CalcPrecoPrazoWS();

 string valorUrl = client.Url;

Browser other questions tagged

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