Jump to content

How to change a web service URL at runtime


Guest lightowl

Recommended Posts

Guest lightowl

I'm playing with a simple smartphone app that communicates with a server application on a PC when connected via ActiveSync.

The server app exposes a web service which I connect to in my client by adding a web reference to the project and letting VS.Net generate a proxy class for me.

This works fine on my dev system, where the server address is always the same as that used in the web service. However, if this is going to be useable on any PCs other than mine, I want the user to be able to configure the server URL at run time.

From what I can gather from MSDN, I'd expect this to be as simple as setting the [proxyclass].Url property but this just causes the proxy class to throw a NullReferenceException whenever I try to use it after setting the Url property.

e.g.

- User starts Smartphone client app

- at this point, [proxyclass].Url == http://MyDevMachine:port/WebService

- An exception is thrown as the user doesn't have access to MyDevMachine

- This exception is caught and the user is prompted for an alternative address

- User enters the correct address for their server.

- the client sets [proxyclass].Url to the address provided by the user

- at this point, I would expect the app to be able to use the webservice, but whenever I call a webservice method on the proxy class, a NullReferenceException is thrown.

Has anyone got any suggestions as to what I'm doing wrong? Or anywhere else I should look?

Thanks,

LightOwl

Link to comment
Share on other sites

  • 1 year later...
Guest paulgyro
I'm playing with a simple smartphone app that communicates with a server application on a PC when connected via ActiveSync.

The server app exposes a web service which I connect to in my client by adding a web reference to the project and letting VS.Net generate a proxy class for me.

This works fine on my dev system, where the server address is always the same as that used in the web service. However, if this is going to be useable on any PCs other than mine, I want the user to be able to configure the server URL at run time.

From what I can gather from MSDN, I'd expect this to be as simple as setting the [proxyclass].Url property but this just causes the proxy class to throw a NullReferenceException whenever I try to use it after setting the Url property.

e.g.

- User starts Smartphone client app

- at this point, [proxyclass].Url == http://MyDevMachine:port/WebService

- An exception is thrown as the user doesn't have access to MyDevMachine

- This exception is caught and the user is prompted for an alternative address

- User enters the correct address for their server.

- the client sets [proxyclass].Url to the address provided by the user

- at this point, I would expect the app to be able to use the webservice, but whenever I call a webservice method on the proxy class, a NullReferenceException is thrown.

Has anyone got any suggestions as to what I'm doing wrong? Or anywhere else I should look?

Thanks,

LightOwl

<{POST_SNAPBACK}>

The proxy generated when you add a web reference has the URL hard coded in the class constructor. What I do it overload (create a 2nd constructor) that accepts a URL that I pass in. Easy as pie!

Link to comment
Share on other sites

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now
×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.