views:

198

answers:

4

This might sound like a silly question, but when I search for webservices, I get no information about how to create them in a windows forms application.

The only result is how to create and expose them by creating an .aspx page.

So my questions is: Can you create and expose webservices within a windows forms application or are they somehow tied in with .asp pages?

Thanks!

later edit: Is there an example of how to create a webservice in a .cs file and not in a .aspx file?

+1  A: 

First, It is not a silly question at all.

are they somehow tied in with .asp pages?

Webservices are not tied to any other application. A WebService is an could be an Application itself. You can create a WebService as a part of a solution, which may have any other type of application like Asp.Net WebApplication or no other application at all.

You can consume a Webservice form any of the following but not limited to

  • Console Application
  • Asp.Net Web Application
  • Windows Forms Application

This article might help

Asad Butt
Thanks for the quick response. Is there an example of how to create a webservice in a .cs file and not in a .aspx file?
Andrei
It looks like he's asking about hosting W/S, not just consuming... WCF is the shortest path AFAIK.
Jim Leonardo
-1: not only is the linked article about consuming a web service and not calling it; the article is also about ASMX web services, which are now considered by Microsoft to be "legacy technology".
John Saunders
A web service is also not an application, not even in legacy ASP.NET/ASMX (it's just a class that's instantiated by an HTTP handler). You could, technically, host a WCF service using the `netTcpBinding` and a `ServiceHost` inside a Windows Forms application. Not sure why you'd *want* to, but it's wrong to say that web services need to be dedicated applications, it's very common to host them as part of a Windows Service.
Aaronaught
Thanks mate for correction
Asad Butt
+2  A: 

I would like to say that a WebService is a service interface into your application, not the application itself.

For exposing a WebService in another hosting enviornment than IIS (where your ASP.Net pages are hosted) you can use the following;

If you are using the WCF toolkit from Microsoft, this means; Create a 'ServiceHost' (actual class name) that can host your webservice implementation. This can be done in any application (ASP.Net pages, Winform, NT Service and even a console application).

Hope this helps,

Marvin Smit
+1  A: 

Traditionally with .net Web Services were implemented using asp.net asmx files hosted in iis. With .net 3 came WCF which allows a range of different types of services (not just web services) hosted in a range of .net applications and services, not just iis. WCF is a complex and powerful set of technologies i have found this book to be helpful

Ben Robinson
WCF is more complicated for two reasons:1) They wanted to include a plethora of options and 2) By not requiring hosting in IIS, it has to take up some infrastructure duties. However, this last point is exactly the reason why you can host it in WinForms. I haven't done it myself, but have been part of a project where it was done. It also allows you to ask the question "Do I really want to use SOAP, or some other message medium?"
Jim Leonardo
A: 

This SO question may help, seems like what you're asking for, presuming a WCF approach.

Jim Leonardo