Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / ASP.NET / Web Services / February 2007

Tip: Looking for answers? Try searching our database.

Dynamic Web Service URL Reference

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
David Morris - 16 Feb 2007 01:19 GMT
Can anyone help me define a dynamic Web Service URL reference in a class
library C# project? I am using Visual Studio 2005/.NET 2.0 and msbuild on a
build server. What I would like is build application so that Web Service
references don't have to be modified in different environments (developer
workstation, build server to test/prod, etc.) The only way I have found to do
this is to search and replace the URL.

In .NET 1.1 projects we could change to dyanmic urls to reference the URL as
a System.Configuration.ConfigurationSettings.AppSettings property. With 2.0
that doesn't appear to be an option.

Thank you,

David Morris
Walter Wang [MSFT] - 16 Feb 2007 02:18 GMT
Hi David,

In .NET 2.0, the webservice URL is still stored in your configuration file
(web.config or app.config). If you open the generated "Reference.cs", you
will see code like following:

       public Service() {
           this.Url =
global::ConsoleApplication1.Properties.Settings.Default.ConsoleApplication1_
localhost_Service;

It's now using a strong typed Setting named
"ConsoleApplication1_localhost_service" which can be modified using the
Setting Designer in Visual Studio 2005:

http://msdn2.microsoft.com/en-us/library/aa730869(vs.80).aspx

If you open the App.config, you will see:

   <configSections>
       <sectionGroup name="applicationSettings"
type="System.Configuration.ApplicationSettingsGroup, System,
Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" >
           <section name="ConsoleApplication1.Properties.Settings"
type="System.Configuration.ClientSettingsSection, System, Version=2.0.0.0,
Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false"
/>
       </sectionGroup>
   </configSections>
   <applicationSettings>
       <ConsoleApplication1.Properties.Settings>
           <setting name="ConsoleApplication1_localhost_Service"
serializeAs="String">
               
<value>http://localhost:4799/WebService1/Service.asmx</value>
           </setting>
       </ConsoleApplication1.Properties.Settings>
   </applicationSettings>

This is called Application Settings:

http://msdn2.microsoft.com/en-us/library/a65txexh(VS.80).aspx

To modify this config using Msbuild, please refer to following article:

http://geekswithblogs.net/paulwhitblog/archive/2006/04/11/74844.aspx

It has some msbuild task to let you easily update the config file when
building the project.

Hope this helps.

Sincerely,
Walter Wang (wawang@online.microsoft.com, remove 'online.')
Microsoft Online Community Support

==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscriptions/managednewsgroups/default.aspx#notif
ications. If you are using Outlook Express, please make sure you clear the
check box "Tools/Options/Read: Get 300 headers at a time" to see your reply
promptly.

Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscriptions/support/default.aspx.
==================================================

This posting is provided "AS IS" with no warranties, and confers no rights.
David Morris - 16 Feb 2007 04:47 GMT
Thank you for responding so quickly.

I should have put more emphasis on the msbuild and class library part.
Getting this to work when Visual Studio is installed isn't a problem. Where
we run into problems is on our build server. It runs msbuild when a developer
code change is detected. When the change is detected the application is
recompiled, tested and pushed up to test/user acceptance/prod as appropriate.

I will try the
http://geekswithblogs.net/paulwhitblog/archive/2006/04/11/74844.aspx
suggestion but I am not too hopeful since the reference is not in a .dll and
not an .exe where the app.config is used. I think the reference that is used
comes from the Settings.Designer. Even changing the settings file doesn't
seem to work. From what I have seen, the custom tool that maintains the
Settings.designer.cs only gets called on a change in Visual Studio 2005 and
not during an msbuild.

Thanks,

David Morris
Walter Wang [MSFT] - 16 Feb 2007 05:36 GMT
Hi David,

You're right that by default, although a Class Library has an app.config in
project file list, at runtime it will not be used since normally a Class
Library dll will not have a separate configuration file.

A workaround is to move the Application Settings section in the Class
Library's app.config into its standalone xml config file; when this Class
Library is used by an EXE, the .exe.config could also link the standalone
xml config file into it. Then remaining job is how to change the standalone
xml config file of the Class Library using MSBUILD task. Please refer to
following thread on how to achieve this.

http://msdn.microsoft.com/newsgroups/managed/default.aspx?dg=microsoft.publi
c.dotnet.languages.csharp&mid=8517fc7f-3952-488c-a772-6111efc14fd0&p=1

Let me know if you have any questions on it.

Regards,
Walter Wang (wawang@online.microsoft.com, remove 'online.')
Microsoft Online Community Support

==================================================
When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.
==================================================

This posting is provided "AS IS" with no warranties, and confers no rights.

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.