Consuming ASP.NET web service from WinForms application

  • Thread starter Johnny Jörgensen
  • Start date
J

Johnny Jörgensen

OK, I have to do a Winforms application (C# or VB doesn't matter - that's
not the important point here) that interacts with a database on a web server
using an ASP.NET web service.

I've done a lot of WinForms programming, but never Web Services. Got a book
about it but that one only talks about how to use the web service from
ASP.NET web applications.

I assume it's pretty much the same from a windows forms app that I have to
add a web reference to my Web service.

BUT:

1) What happens if the web service is not available because the computer
running the app is not connected to the internet? Will the app crash or can
it continue if the web service referenced is not available?

2) Can I define classes in my web service and have the web service return an
instace of that class? Will my windows app be able to recognize classes
defined in a web service?

I hope somebody can answer this for me, because I have to get started now,
and I could really use any tips you might have. Is there something else I
should think of?

Cheers,
Johnny J.
 
A

Alberto Poblacion

Johnny Jörgensen said:
1) What happens if the web service is not available because the computer
running the app is not connected to the internet? Will the app crash or
can it continue if the web service referenced is not available?

If the server is not available, you will get an exception when making
any call to the webservice. The exception can be caught by means of
try...catch.
2) Can I define classes in my web service and have the web service return
an instace of that class? Will my windows app be able to recognize classes
defined in a web service?

Yes. When you add a Reference to the web service, a local definition for
the remote class will be created in your project along with the proxy class
for the webservice. Note that only the data in the class will be
"transported". If the class defines methods on the server, those methods
will not be available to the local "copy" of the class.
I hope somebody can answer this for me, because I have to get started now,
and I could really use any tips you might have. Is there something else I
should think of?

Note that when your web service returns an instance of the class, you
don't get a reference to the original object, but the serialized contents
that are then deserialized into a local copy. So the semantics are somewhat
different to what you would get if you were doing a local call, even though
the syntax of the call looks the same on your source code.
 

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

Top