5-12-2008 9:22:52
Bác ơi, em đang tìm hiểu về cái webservice. Nhưng chưa biết làm thế nào cả,
Bác có tài liệu hay biết về vấn đề này thì chỉ giúp em với. Cần những công cụ nào để thực hiện được ạ. Em cám ơn nhìu
---
using System;
using System.Web;
using System.Collections;
using System.Web.Services;
using System.Web.Services.Protocols;
/// <summary>
/// Summary description for ws
/// </summary>
[WebService(Namespace = "http://awas.vn/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
public class ws : System.Web.Services.WebService
{
public ws()
{
//Uncomment the following line if using designed components
//InitializeComponent();
}
[WebMethod]
public string HelloWorld()
{
return "Hello World";
}
[WebMethod]
public int Add(int a, int b)
{
return (a + b);
}
}

Viết đoạn code này vứt vào file ws.asmx trong 1 cái web project nào đó. Coi nó là server. Còn client thì add cái web reference vào

Nó sẽ ra cái hình như sau:

Nhớ bấm và cái Add Reference nhé.
Rõ ràng chúng ta nhìn thấy cái hàm add mới viết. Và trong code tại client chúng ta cứ thế mà gọi ra thôi.