Making a dynamic web service call

  • Thread starter Maziar Aflatoun
  • Start date
M

Maziar Aflatoun

Hi,

Is there a way to connect to a Web Service dynamically at runtime (Web
Reference URL)? I have always used Visual Studio to create a Web Reference
and then used it in my code. However, that always requires the URL to the
Web Service to be the same on the staging site and the production site. Now
I have two instances of the same application running (Staging site and
Production) and want to store the URL in a file instead. Is there a way to
do this?

ex. Web.Config AppSetting <add key="WebServiceURL"
Value=http://....webserv.asmx>

Thank you
Maz.
 
B

Brock Allen

You can use wsdl.exe to generate the proxy instead and use the /urlkey:SomeKey
command line parameter. "SomeKey" will be the element in <appSettings> where
you've stored the URL. The proxy will then automatically read <appSettings?
to fetch the URL. The other option is to manually set the Url property on
the proxy from you code prior to invoking it.
 
M

Maziar Aflatoun

Thanks found an easier way

In the properties window of the Web Reference set the property

URL Behavior = Dynamic

This will put an entry into the app.config file that looks something like
this:

<add key="MyApp.TestService.TestService"
value="http://MyServer/MyVirtualDir/MyService.asmx"/>

Which can be edited to reflect the server you wish to work on either in the
app.config directly or in the Web Reference properties again by changing the
Web Reference URL property

Maz.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,997
Messages
2,570,241
Members
46,830
Latest member
HeleneMull

Latest Threads

Top