views:

69

answers:

1

Hi,

I am using asp.net mvc to create forms validated restful webservices.

I am just wondering whether it is possible to consume these web services via, for example, a console application? How do I create the cookie etc.

Ultimately I would like to unit test the actual web services.

Thanks a lot.

christian

A: 

I am just wondering whether it is possible to consume these web services via, for example, a console application?

certainly you can

Sample webservice

    [WebService(Namespace = "http://localhost/MyWebService/")]
    public class MyWebService : WebService
    {
        [WebMethod]
        public int Add(int a, int b)
        {
            return a + b;
        }

        [WebMethod]
        public String SayHello()
        {
            return "Hello World";
        }
    }

Here is how to consume it from a console application

  public static void Main(String[] args)
  {
      MyWebService  service = new MyWebService  ();
      mySvc.SayHello();          
      mySvc.Add(2, 3).ToString();
  }

see this article for detailed sample

.NET Web Services Tutorial

Asad Butt
Thanks for the reply. The problem is that the restful web services are forms validated. So the console application has to simulate the login process (store cookie? etc.).Thanks.
csetzkorn
A console application is almost identical to a Winforms application with only UI difference. So we have to do more for user interaction with app. If you need to provide better interface, use Winforms then.
Asad Butt
Thanks. The web service (exposed via asp.net mvc and secured via forms validation) shall be consumed by humans and machines. The latter use 'console apps' to achieve this. The question is how can I simulate the authentication process in a console app. so winforms is not really relevant.
csetzkorn