我正在使用 asp.net mvc 创建经过表单验证的 restful web 服务。
我只是想知道是否可以通过控制台应用程序等方式使用这些 Web 服务?如何创建 cookie 等。
最终我想对实际的网络服务进行单元测试。
最佳答案
I am just wondering whether it is possible to consume these web services via, for example, a console application?
当然可以
示例网络服务
[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";
}
}
以下是如何从控制台应用程序
使用
public static void Main(String[] args)
{
MyWebService service = new MyWebService ();
mySvc.SayHello();
mySvc.Add(2, 3).ToString();
}
详细示例请看这篇文章
关于c# - 使用/单元测试表单验证 Restful 网络服务,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2355263/