在HTML页面通过webservice.htc调Webservice
HTML代码如下:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >
<HTML>
<HEAD>
<TITLE></TITLE>
<META NAME="GENERATOR" Content="Microsoft Visual Studio 7.0">
<Link href="../Css/style.css" rel="stylesheet"></Link>
<script language="javascript">
var iCallID = 0;
function Init()
{
service.useService("http://ming.europe.webmatrixhosting.net/MingWService/Caculate.asmx?WSDL","Caculate");
}
function mathResults(result)
{
// if there is an error, and the call came from the call() in init()
if(result.error)
{
// Pull the error information from the event.result.errorDetail properties
var xfaultcode = result.errorDetail.code;
var xfaultstring = result.errorDetail.string;
var xfaultsoap = result.errorDetail.raw;
// Add code to handle specific error codes here
txtResult.value = "Something Error ";
}
// if there was no error
else
{
// Show the arithmetic
//alert(intA + ' + ' + intB + " = " + result.value);
txtResult.value = result.value;
}
}
function Add(a,b)
{
DisbleButton();
txtResult.value = "Calculating Now ";
iCallID = service.Caculate.callService(mathResults, "Add", a, b);
EnableButton();
}
function Subtract(a,b)
{
DisbleButton();
txtResult.value = "Calculating Now ";
iCallID = service.Caculate.callService(mathResults, "Subtract", a, b);
EnableButton();
}
function Multiply(a,b)
{
DisbleButton();
txtResult.value = "Calculating Now ";
iCallID = service.Caculate.callService(mathResults, "Multiply", a, b);
EnableButton();
}
function Divide(a,b)
{
DisbleButton();
txtResult.value = "Calculating Now ";
iCallID = service.Caculate.callService(mathResults, "Divide", a, b);
EnableButton();
}
function DisbleButton()
{
btnAdd.disabled = true;
btnSubtract.disabled = true;
btnMultiply.disabled = true;
btnDevide.disabled = true;
}
function EnableButton()
{
btnAdd.disabled = false;
btnSubtract.disabled = false;
btnMultiply.disabled = false;
btnDevide.disabled = false;
}
</script>
</HEAD>
<BODY onload="Init()">
<div id="service" style="BEHAVIOR:url(../Htc/webservice.htc)"></div>
<FONT face="宋体"></FONT>
<TABLE id="Table1" cellSpacing="1" cellPadding="1" width="100%" border="0">
<TR>
<TD align="middle" valign="center">
<TABLE id="Table2" cellSpacing="1" cellPadding="1" width="80%" border="0">
<TR>
<TD></TD>
</TR>
<TR>
<TD>float a:<INPUT id="txtA" class="text" type="text" name="txtA"></TD>
</TR>
<TR>
<TD>float b:<INPUT id="txtB" class="text" type="text" name="txtB"></TD>
</TR>
<TR>
<TD>
<INPUT id="btnAdd" type="button" onclick="Add(txtA.value,txtB.value)" value="Add" name="btnAdd">
<INPUT id="btnSubtract" type="button" onclick="Subtract(txtA.value,txtB.value)" value="Subtract" name="btnSubtract">
<INPUT id="btnMultiply" type="button" onclick="Multiply(txtA.value,txtB.value)" value="Multiply" name="btnMultiply">
<INPUT id="btnDevide" type="button" onclick="Divide(txtA.value,txtB.value)" value="Devide" name="btnDevide"></TD>
</TR>
<TR>
<TD>Result:<INPUT id="txtResult" class="text" type="text" name="txtResult"></TD>
</TR>
</TABLE>
</TD>
</TR>
</TABLE>
</BODY>
</HTML>
<HTML>
<HEAD>
<TITLE></TITLE>
<META NAME="GENERATOR" Content="Microsoft Visual Studio 7.0">
<Link href="../Css/style.css" rel="stylesheet"></Link>
<script language="javascript">
var iCallID = 0;
function Init()
{
service.useService("http://ming.europe.webmatrixhosting.net/MingWService/Caculate.asmx?WSDL","Caculate");
}
function mathResults(result)
{
// if there is an error, and the call came from the call() in init()
if(result.error)
{
// Pull the error information from the event.result.errorDetail properties
var xfaultcode = result.errorDetail.code;
var xfaultstring = result.errorDetail.string;
var xfaultsoap = result.errorDetail.raw;
// Add code to handle specific error codes here
txtResult.value = "Something Error ";
}
// if there was no error
else
{
// Show the arithmetic
//alert(intA + ' + ' + intB + " = " + result.value);
txtResult.value = result.value;
}
}
function Add(a,b)
{
DisbleButton();
txtResult.value = "Calculating Now ";
iCallID = service.Caculate.callService(mathResults, "Add", a, b);
EnableButton();
}
function Subtract(a,b)
{
DisbleButton();
txtResult.value = "Calculating Now ";
iCallID = service.Caculate.callService(mathResults, "Subtract", a, b);
EnableButton();
}
function Multiply(a,b)
{
DisbleButton();
txtResult.value = "Calculating Now ";
iCallID = service.Caculate.callService(mathResults, "Multiply", a, b);
EnableButton();
}
function Divide(a,b)
{
DisbleButton();
txtResult.value = "Calculating Now ";
iCallID = service.Caculate.callService(mathResults, "Divide", a, b);
EnableButton();
}
function DisbleButton()
{
btnAdd.disabled = true;
btnSubtract.disabled = true;
btnMultiply.disabled = true;
btnDevide.disabled = true;
}
function EnableButton()
{
btnAdd.disabled = false;
btnSubtract.disabled = false;
btnMultiply.disabled = false;
btnDevide.disabled = false;
}
</script>
</HEAD>
<BODY onload="Init()">
<div id="service" style="BEHAVIOR:url(../Htc/webservice.htc)"></div>
<FONT face="宋体"></FONT>
<TABLE id="Table1" cellSpacing="1" cellPadding="1" width="100%" border="0">
<TR>
<TD align="middle" valign="center">
<TABLE id="Table2" cellSpacing="1" cellPadding="1" width="80%" border="0">
<TR>
<TD></TD>
</TR>
<TR>
<TD>float a:<INPUT id="txtA" class="text" type="text" name="txtA"></TD>
</TR>
<TR>
<TD>float b:<INPUT id="txtB" class="text" type="text" name="txtB"></TD>
</TR>
<TR>
<TD>
<INPUT id="btnAdd" type="button" onclick="Add(txtA.value,txtB.value)" value="Add" name="btnAdd">
<INPUT id="btnSubtract" type="button" onclick="Subtract(txtA.value,txtB.value)" value="Subtract" name="btnSubtract">
<INPUT id="btnMultiply" type="button" onclick="Multiply(txtA.value,txtB.value)" value="Multiply" name="btnMultiply">
<INPUT id="btnDevide" type="button" onclick="Divide(txtA.value,txtB.value)" value="Devide" name="btnDevide"></TD>
</TR>
<TR>
<TD>Result:<INPUT id="txtResult" class="text" type="text" name="txtResult"></TD>
</TR>
</TABLE>
</TD>
</TR>
</TABLE>
</BODY>
</HTML>