Having trouble changing a web service URL at runtime

G

Guest

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. The web service is generated by setting up a .Net Remoting
channel because I don't want my app to require an IIS installation.

This works fine on my dev system, where the service address is always the
same as that used in the original web reference. 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,

Ed
 
A

Alex Feinman [MVP]

Well, the error must be somewhere in your code. E.g. when exception is
thrown (I assume it is a WebException or it's descendant), your code flow
gets interrupted and something does not get executed. Post more code or run
under debugger to see what exactly causes the nullReferenceException to be
thrown. While doing this, in the generated proxy remove
[System.Diagnostics.DebuggerStepThroughAttribute()] to be able to step into
the proxy code
 
G

Guest

Thanks Alex,

Your advice helped me solve the problem... I wasn't aware of the
[System.Diagnostics.DebuggerStepThroughAttribute()] - as soon as I removed
this as you suggested, I was able to step through the generated code and see
that it was all down to a stupid mistake in my server code.

Ed
 

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