spicy.net: How to make your Web Reference proxy URL dynamic

spicy.net

Friday, May 19, 2006

How to make your Web Reference proxy URL dynamic

I have been facing a problem in my project that how to make the URL property for a web reference to a web service, configurable in a config file instead of compiled in the web reference proxy. This is most useful when you want to deploy a project with a web reference between different business environments (like between Testing/QA and Production) without recompiling the project. There is a simple way to do this that requires no coding at all on the developer's part (provided you are using Visual Studio for .NET).
Step1:
Add web service reference in your project After you have added your web reference (which creates the proxy class with references to the web service for you automatically using VS .NET), you need to set your solution view to 'Show All':This shows the Reference.cs file for the Reference.map. This is the proxy class file that VS.NET generates automatically for you when you add a web reference.

Step2:
If you look at the web reference properties you can see that there is a configuration setting called 'URL Behavior'. This setting is by default set to Static. we need to change this setting to Dynamic.Doing this in VS.NET does two things for you. It changes the Reference.cs file to have the code to look for the WSDL URL in the project's web.config file Now you can set the URL to different servers for deployment in different environments, without having to change the code. You just change the URL in your config file for your project.

Sample:



1 Comments:

  • Nice blog.Useful for creating such a dynamic behaviour of the services in the dynamic world..No more to be static...:)

    By Blogger Sheik, at 3:36 PM  

Post a Comment

<< Home