Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

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...

George C.K. Low

Posted
You could store the address in either a textfile or the registry, then simply look up the address when you boot up the program.
Anybody looking for a graduate programmer (Midlands, England)?
Posted

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?

Anybody looking for a graduate programmer (Midlands, England)?
  • Administrators
Posted

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.

Posting Guidelines FAQ Post Formatting

 

Intellectuals solve problems; geniuses prevent them.

-- Albert Einstein

Posted

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

George C.K. Low

  • Administrators
Posted

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.

Posting Guidelines FAQ Post Formatting

 

Intellectuals solve problems; geniuses prevent them.

-- Albert Einstein

  • 4 weeks later...
Posted

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:

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:

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:

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:

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.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...