[WebMethod]
public int DoMulti(int num1,int num2)
{
int result;
result = num1 * num2;
return result;
}
<%@ Page language="c#" Codebehind="Javascript.aspx.cs" AutoEventWireup="false" Inherits="WebTest.Javascript" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >
<HTML>
<HEAD>
<title>Javascript</title>
<meta name="GENERATOR" Content="Microsoft Visual Studio .NET 7.1">
<meta name="CODE_LANGUAGE" Content="C#">
<meta name=vs_defaultClientScript content="JavaScript">
<meta name=vs_targetSchema content="http://schemas.microsoft.com/intellisense/ie5">
<script language="javascript">
function doMul(){
service.useService("http://localhost/WebServiceTest/Multi.asmx?wsdl","DoMultiService");
var parm1 = Form1.all.mul1.value;
var parm2 = Form1.all.mul2.value;
service.DoMultiService.callService(callback,"DoMulti",parm1,parm2);
}
function callback(res){
if (!res.error)
Form1.all.retValue.value=res.value;
else
Form1.all.retValue.value='ERR';
}
</script>
</HEAD>
<body>
<div id="service" style="BEHAVIOR:url(webservice.htc)"></div>
<form id="Form1" method="post" runat="server"><FONT
face=宋体><INPUT type=text id=mul1 name=mul1>*<INPUT type=text id=mul2 name=mul2><INPUT style="WIDTH: 50px" onclick=doMul() type=button value="="><INPUT
type=text id=retValue name=retValue></FONT>
</form>
</body>
</HTML>
其中 webservice.htc 需要另外下载
http://msdn.microsoft.com/workshop/author/webservice/webservice.htc