468,727 Members | 1,619 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,727 developers. It's quick & easy.

Conditional Web Service instantiation

I work in a shop with up to three environments for the development/deployment
process. Each environment has its own db and web servers and its own web
services servers as well.

I am developing a .NET component as part of the application that calls one
of the web services for some of its functionailty. Currently, I have to
update the web service reference for the dev environment, compile the
component and deploy to the dev web server for testing/debug. Then, once the
code has been tested and debugged, before we can deploy it to the demo
environment I hate to change the URL for the web service, and recompile the
code to create a new install package for the demo environment. Then, for
changes and fixes, I have to change the web service URL back to the dev
environment and recompile the code and reinstall on the dev server.

If this was a windows app, I know we can control the web service url ion the
app.config file. However, my testing seems to indicate that does not work for
a component (DLL).

Is there some easier way to handle this so that I can code teh component
with both URLs and let it decide which webs service to call at runtime?

Aug 28 '07 #1
4 1681
"John Beschler" <Jo**********@discussions.microsoft.comwrote in message
news:D4**********************************@microsof t.com...
>I work in a shop with up to three environments for the
development/deployment
process. Each environment has its own db and web servers and its own web
services servers as well.

I am developing a .NET component as part of the application that calls one
of the web services for some of its functionailty. Currently, I have to
update the web service reference for the dev environment, compile the
component and deploy to the dev web server for testing/debug. Then, once
the
code has been tested and debugged, before we can deploy it to the demo
environment I hate to change the URL for the web service, and recompile
the
code to create a new install package for the demo environment. Then, for
changes and fixes, I have to change the web service URL back to the dev
environment and recompile the code and reinstall on the dev server.

If this was a windows app, I know we can control the web service url ion
the
app.config file. However, my testing seems to indicate that does not work
for
a component (DLL).

Is there some easier way to handle this so that I can code teh component
with both URLs and let it decide which webs service to call at runtime?
One way would be for the component to expose a Url property. This property
could set the Url of the proxy class.

Another thing would be for the component to require a particular appSettings
key in the .config file of the application that uses the component.

Finally, if you are using .NET 2.0, then I've heard that using the new
Settings architecture will resolve this problem for you. In that case, the
component itself would hold the definitions of the settings, along with
their default values. If the setting existed in a config file, then it would
be used, otherwise, it would be created when the component settings are
persisted.

Caveat: I haven't tried this myself with a component.
--
John Saunders [MVP]

Aug 28 '07 #2
John,

Thanks for the reply. I had actually considered using a property to select
which URL; however, I was unable to figure out a way to create the reference.
Could you point me to some examples of how to do this?

Thanks,
John Beschler
"John Saunders [MVP]" wrote:
"John Beschler" <Jo**********@discussions.microsoft.comwrote in message
news:D4**********************************@microsof t.com...
I work in a shop with up to three environments for the
development/deployment
process. Each environment has its own db and web servers and its own web
services servers as well.

I am developing a .NET component as part of the application that calls one
of the web services for some of its functionailty. Currently, I have to
update the web service reference for the dev environment, compile the
component and deploy to the dev web server for testing/debug. Then, once
the
code has been tested and debugged, before we can deploy it to the demo
environment I hate to change the URL for the web service, and recompile
the
code to create a new install package for the demo environment. Then, for
changes and fixes, I have to change the web service URL back to the dev
environment and recompile the code and reinstall on the dev server.

If this was a windows app, I know we can control the web service url ion
the
app.config file. However, my testing seems to indicate that does not work
for
a component (DLL).

Is there some easier way to handle this so that I can code teh component
with both URLs and let it decide which webs service to call at runtime?

One way would be for the component to expose a Url property. This property
could set the Url of the proxy class.

Another thing would be for the component to require a particular appSettings
key in the .config file of the application that uses the component.

Finally, if you are using .NET 2.0, then I've heard that using the new
Settings architecture will resolve this problem for you. In that case, the
component itself would hold the definitions of the settings, along with
their default values. If the setting existed in a config file, then it would
be used, otherwise, it would be created when the component settings are
persisted.

Caveat: I haven't tried this myself with a component.
--
John Saunders [MVP]

Aug 28 '07 #3
"John Beschler" <Jo**********@discussions.microsoft.comwrote in message
news:17**********************************@microsof t.com...
John,

Thanks for the reply. I had actually considered using a property to select
which URL; however, I was unable to figure out a way to create the
reference.
Could you point me to some examples of how to do this?
Just use Add Web Reference as normal. This creates a proxy class that
derives from the HttpWebClientProtocol class. That is the class with the
Url property. So:

public class MyComponent : IDisposible
{
private localhost.Server _proxyInstance;
private string _url;

public string Url
{
get {return _url;} set {_url = value;}
}

public void MethodThatCallsWS()
{
if (_proxyInstance == null)
{
_proxyInstance = new localhost.Server();
}

_proxyInstance.Url = Url;

_proxyInstance.WebMethod();
}

void IDisposible.Dispose()
{
if (_proxyInstance != null)
{
((IDisposible) _proxyInstance).Dispose();
}
}
}
--
John Saunders [MVP]

Aug 28 '07 #4
That worked!!!!!
Thanks so much for the help!!!1

John
"John Saunders [MVP]" wrote:
"John Beschler" <Jo**********@discussions.microsoft.comwrote in message
news:17**********************************@microsof t.com...
John,

Thanks for the reply. I had actually considered using a property to select
which URL; however, I was unable to figure out a way to create the
reference.
Could you point me to some examples of how to do this?

Just use Add Web Reference as normal. This creates a proxy class that
derives from the HttpWebClientProtocol class. That is the class with the
Url property. So:

public class MyComponent : IDisposible
{
private localhost.Server _proxyInstance;
private string _url;

public string Url
{
get {return _url;} set {_url = value;}
}

public void MethodThatCallsWS()
{
if (_proxyInstance == null)
{
_proxyInstance = new localhost.Server();
}

_proxyInstance.Url = Url;

_proxyInstance.WebMethod();
}

void IDisposible.Dispose()
{
if (_proxyInstance != null)
{
((IDisposible) _proxyInstance).Dispose();
}
}
}
--
John Saunders [MVP]

Aug 28 '07 #5

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

12 posts views Thread by mlimber | last post: by
2 posts views Thread by Gregory Gadow | last post: by
4 posts views Thread by Bob | last post: by
20 posts views Thread by =?Utf-8?B?cmtibmFpcg==?= | last post: by
1 post views Thread by =?Utf-8?B?YQ==?= | last post: by
1 post views Thread by CARIGAR | last post: by
reply views Thread by zhoujie | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.