先用C#建立一个WebService代码如下:
/// <summary>
///TestService 的摘要说明
/// </summary>
[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
public class TestService : System.Web.Services.WebService
{
public TestService ()
{
//如果使用设计的组件,请取消注释以下行
//InitializeComponent();
}
[WebMethod]
public int Add(int x, int y) {
return x + y;
}
}
Asp调用WebService代码如下:
<%
dim url
url = "http://××××××××××/TestService.asmx/Add"
dim postdata
postdata = "x=8&y=10"
dim xmlhttp
Set xmlhttp = server.CreateObject("Msxml2.XMLHTTP")
xmlhttp.Open "POST",url,false
xmlhttp.setRequestHeader "Content-Type", "application/x-www-form-urlencoded"
xmlhttp.setRequestHeader "Content-Length",LEN(postdata)
xmlhttp.send(postdata)
Response.Write xmlhttp.Status & " "
Response.Write xmlhttp.StatusText
Set xmlhttp = Nothing
%>
用C#的调用方式比较麻烦了。