Need to create dynamic Web Reference from XML Web Service consumer application

You can configure the web service to pull the URL based on a setting in a
configuration file, rather than a hardcoded value. To change the location,
simply change the config file with no recompile.

Here’s how to do it:
Add your web reference. Go to "Solution Explorer", right click on the web
reference name (eg. "localhost") and choose properties. In the property
window change "Url Behavior" from "Static" to "Dynamic".

If the web service client is a non-web application, this will automatically
create a file name app.config with the URL to the web service.


value="http://localhost/mywebservice/service1.asmx"


After you comiple your client app, the configuration file of it (such as
something.exe.config) will have the same content as the app.config.
Now, you can deploy the configuration along with the client executable. If
you ever need to change the web service location, you can open the
something.exe.config file in notepad and change the value attribute.

If the web service client is a web application such as asp.net web form,
changing "Url Behavior" from "Static" to "Dynamic" will automatically add
the same appsettings to web.config. Now, if you ever need to change the web
service location, you can open web.config file in notepad and change the
value attribute.

For Service URLs that change more often or at runtime, you can write custom
code to change the URL property off of the proxy class.

e.g.

ws.GetCustomers()
ws.Url = CompatibleCustomerServices(2) //bind to a the next compatible
service in the list
ws.GetCustomers()

Note:
Outside VS.NET, you can use "wsdl.exe /urlkey:
to generatea proxy which
automatically checks in the for the given key.

When using "wsdl.exe /urlkey:myapplication.mywebservice.service1
for example, you should be
able to use the following configuration file to read the URL without any
further manual changes needed:



value=" />


No comments:

Ramadan - What is it?

  Ramadan is one of the most important and holy months in the Islamic calendar. It is a time of fasting, prayer, and spiritual reflection fo...