ClickOnce reference to web server

C

cathywigzell

I have a small ClickOnce application which communicates with the server
it loaded from. When I created the ClickOnce app, I added a Web
Reference to a .asmx file on the server. The app then uses this
reference to make calls to the server. That all works nicely.

However, at deployment, every server will have a unique name
(obviously). Yet my ClickOnce app will still have its hard-coded web
reference.

How can I change the web reference dynamically? The ClickOnce app must
know the server location (to check for updates) - how can I get hold of
this and then use it to make calls back to the same server? Or, is
there some other way of setting the Web Reference appropriately?

Cathy
 
M

Marc Gravell

For getting the ClickOnce location of a non-installed (online-only)
application:
First check that
System.Deployment.Application.ApplicationDeployment.IsNetworkDeployed is
true - otherwise you aren't running as ClickOnce and nothing can work; after
this you have access to a range of properties on
System.Deployment.Application.ApplicationDeployment.CurrentDeployment, most
noteably UpdateLocation.

(for installed apps, I suspect that the update location may well be burned
into the manifest, so it might return the same value on any server; one to
check if you use this)

For changing the web-service end-point, simply update the WebService URL
property; it is a pain to have to do this each time you create an instance,
so I do something like:

public static class WebServices {
public static T Get<T>() where T :
System.Web.Services.Protocols.SoapHttpClientProtocol, new() {
T service = new T();
service.Url = "something else dynamic"; //TODO: example only
return service;
}
}

This allows me to call WebServices.Get<SomeService> and apply a host of
standard options each time.

Hope this helps,

Marc
 

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

Similar Threads


Top