dynamic web reference

georgepatotk

Contributor
Joined
Mar 1, 2004
Messages
432
Location
Malaysia
I don't know whether this is called dynamic web reference.

My problem is this,

I have a web service in assume http://abc/myservice.asmx, so, i link my program to this address to call the reference.

But, the address will be change from time to time and I don't want to recompile my program just because of the changes of the address.

What i wanna do is write a simple module to store the latest address on the run time, and the reference will refer to theaddress.

Please helps. Thanks...
 
U are right, this is the way. But, how to edit the referece?

I should be doing some thing like

Webreference.URL = "http://abc/Webservice.asmx"

But, where to do this?

Like in database, we have

conn.ConnectionString = "bla bla bla"
 
Well I'm not going to pretend to know anything much about web development, so if I speak nonesense then just ignore me.

When you say WebReference are you talking about a System.Web.Services.Description.WebReference object or something else?
 
If you added the web reference via VS then you can select the webreference through the solution explorer and in the property grid change it from static to dynamic.
This will move the URL to the appropriate config file (web.config or app.config) for you.
 
Dear PlausiblyDamp,

Yes, I had change the URL from static to Dynamic but it is not working still.

Let me tell u my case,

I did like this,
ws.URL = "http://192.168.0.155/Webservice/Ordering.asmx"

but, it doesn't works. And for ur information, this is not a web application so, it doesn't have web config and app config.

What I do is like what Cags suggested, store the value into a file and read from the file.

And lastly, my application is a pocket pc application. Please guide me. Thanks
 
If it is a windows application or a console application it will have an app.config file.

The single line of code you posted should work - however without seeing what else you are doing or more details about how it is failing to work it is quite difficult to help.
 
Dear PlausiblyDamp,

I problem here is after i change the property to dynamic, the app.config file is not automatically generated, and if i store the value into a text file and assign using ws.URL = "http://192.168.0.155/Webservice/Ordering.asmx", it is not working as well.

Please guide me...
 
Use the WSDL tool to generate a proxy class. This essentially does the exact same thing as when you add a Web Reference in Visual Studio -- except that you will now have the underlying .cs file.

The command line call to do this might look something like this:
Code:
wsdl /out:MyWebServiceProxy.cs [url]http://localhost/blah/service.asmx[/url]
This will build the "MyWebServiceProxy.cs" proxy file. Include this in your project and then open up the file. You will notice that the constructor looks like this:
C#:
public Service() 
{
    this.Url = "http://localhost/blah/service.asmx";
}
You will also notice that this is the only location where the Url is set. So I usually just modify the constructor to look something like this:
C#:
public Service(string server)
{
    this.Url = string.Format("http://{0}/blah/service.asmx", server);
}
You can also then wrap the class in your own namespace if you want. From here you can now create an instance of the proxy class with something like the following:
C#:
MyNamespace.ServiceX service = new MyNamespace.ServiceX("localhost");
service.HelloWorld();
You can then set the server reference as needed by creating new instances of the proxy class. All should work well provided that all servers share the same version of the Web Service.
 
Back
Top