How to the override web reference in class library

C

CraigHB

I have a Visual Studio 2005 solution that contains a website and a class
library. The class library has a web reference to a web service. I want to be
able to override the URL used by the class library for its web reference,
ideally by just changing a value in the website's web.config.

Is this possible?
 
M

Marc Gravell

Is this possible?

Yes. If there isn't already an entry in the config, you can certainly
pass arguments to wsdl.exe to specify the config entry to use (and
wsdl.exe has more options that the IDE, anyway)

Marc
 
J

John Saunders [MVP]

CraigHB said:
I have a Visual Studio 2005 solution that contains a website and a class
library. The class library has a web reference to a web service. I want to
be
able to override the URL used by the class library for its web reference,
ideally by just changing a value in the website's web.config.

Is this possible?

Set the Url property of the proxy instance to the URL you want. If you want
your web site to be able to set that Url, then your class library has to
expose a Url property that the caller can set.
 
S

Steven Cheng [MSFT]

Hi craighb,

Yes, sure, you can make the webservice proxy class(defined in class library
project)'s url configurable in your ASP.NET web application, just follow
this way:

** in your class library project(which contains the webservice proxy), open
the app.config file generated by the IDE, you can find the following style
configuration:

==============
<configuration>
<configSections>
<sectionGroup name="applicationSettings"
type="System.Configuration.ApplicationSettingsGroup, System,
Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" >
<section name="ClassLibrary1.Properties.Settings"
type="System.Configuration.ClientSettingsSection, System, Version=2.0.0.0,
Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false"
/>
</sectionGroup>
</configSections>
.........................
<applicationSettings>
<ClassLibrary1.Properties.Settings>
<setting name="ClassLibrary1_wsvc_Service" serializeAs="String">
<value>http://servername/WCFSVC/Service.svc</value>
</setting>
</ClassLibrary1.Properties.Settings>
</applicationSettings>
</configuration>
=================================

the above configuration elements are generated by IDE to store the url of
webservice proxy. To allow any other projects (which reference this class
library and use the webservice proxy) to change the url, you can copy all
the above configuration sections into the target application's
app.config(or web.config for ASP.NET app).

For example, suppose my ASP.NET web application use added reference to the
class library and use that webservice proxy, I can override the proxy url
in web.config as below:

================
<configuration>
<configSections>
<sectionGroup name="applicationSettings"
type="System.Configuration.ApplicationSettingsGroup, System,
Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" >
<section name="ClassLibrary1.Properties.Settings"
type="System.Configuration.ClientSettingsSection, System, Version=2.0.0.0,
Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false"
/>
</sectionGroup>
</configSections>
<connectionStrings>
<add name="ClassLibrary1.Properties.Settings.testdbConnectionString"
connectionString="Data Source=localhost;Initial
Catalog=testdb;Integrated Security=True"
providerName="System.Data.SqlClient" />
</connectionStrings>
<applicationSettings>
<ClassLibrary1.Properties.Settings>
<setting name="ClassLibrary1_wsvc_Service" serializeAs="String">
<value> [ Your overrided new url address here] </value>
</setting>
</ClassLibrary1.Properties.Settings>
</applicationSettings>


<system.web>
....

</system.web>
</configuration>
==================

BTW, since you can programmtically change proxy.Url property, you can also
consider add a simple name/value pair in web.config's AppSettings section
and use code to always assign url from that name/value pair in your ASP.NET
code (where you will call the webservice proxy).

Hope this helps.

Sincerely,

Steven Cheng

Microsoft MSDN Online Support Lead


Delighting our customers is our #1 priority. We welcome your comments and
suggestions about how we can improve the support we provide to you. Please
feel free to let my manager know what you think of the level of service
provided. You can send feedback directly to my manager at:
(e-mail address removed).

==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscriptions/managednewsgroups/default.aspx#notif
ications.

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

--------------------
 

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

Top