例子 把htc放在同一目录下,http://www.xemantex.com/webservice.htc <HTML> <HEAD> <LINK href="baseStyle.css" type="text/css" rel="stylesheet"> <title>Web Services - Create and Consume Demo</title> <SCRIPT language="JavaScript"> function initWebHTC() { //init and create short-cut name for web service dNtWbSvc.useService("http://www.xemantex.com/consumeDnTWebSvc.asmx?WSDL","dNtSvc"); var iCallID; if (dNtWbSvc.dNtSvc) { document.getElementById("lblDateTime").innerHTML="正在加载..." iCallID= dNtWbSvc.dNtSvc.callService(gtDnTRslt,"currDateTime"); } } function gtDnTRslt(result) { //if an error then get error details if(result.error) { //Pull error info from 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 document.getElementById("lblDateTime").innerHTML="Error: " + xfaultcode + " ; " + xfaultstring + " ; " + xfaultsoap; } else { //alert(result.value); document.getElementById("lblDateTime").innerHTML=result.value; //clear any selection var sRng; sRng = document.selection.createRange(); sRng.execCommand("unselect"); } } </SCRIPT> </HEAD> <body onload="initWebHTC();"> <DIV id="dNtWbSvc" style="BEHAVIOR: url(webservice.htc)"></DIV> <span id="lblDateTime" style="background-color:#99EEDD;height:36px;width:581px;">Date and time will be displayed here.</span></td>
</body> </HTML>
使用javascript是可以的,把webservice.htc放在网站目录下 <title>WebForm1</title> <meta content="Microsoft Visual Studio .NET 7.1" name="GENERATOR"> <meta content="Visual Basic .NET 7.1" name="CODE_LANGUAGE"> <meta content="JavaScript" name="vs_defaultClientScript"> <meta content="http://schemas.microsoft.com/intellisense/ie5" name="vs_targetSchema"> <LINK href="Styles.css" type="text/css" rel="stylesheet"> <!--#include file=include\olap.js --> </HEAD> <body onload="InitializePage()" MS_POSITIONING="GridLayout"> <script language="javascript" event="Query" for="PivotTable1"> { var sLog = document.Form1.Text1.value + ""; document.Form1.Text1.value = "Query Event Fired. " + sLog; } </script> <script language="vbscript"> Sub PivotTable1_CommandExecute(Command, Succeeded) Dim ptConstants Set ptConstants = document.Form1.PivotTable1.Constants ' Check to see if the PivotTable list has been refreshed. If Command = ptConstants.plCommandRefresh Then ' Write the current data and time to the text box. document.Form1.Text1.value = vbCrLf & "PivotTable Last Refreshed on " & Date & " at " & Time & vbCrLf & document.Form1.Text1.value End If End Sub </script>附js文件 <script id="iq_olap" language="javascript">
var frm1; var service; // Page initialization code, called from Body onLoad event handler function InitializePage() { service = document.getElementById("service");
// Set page-level variables frm1 = document.forms[0];
// Create an instance of the web service and call it svcOlap service.useService("/services/wsOLAP.asmx?WSDL","svcOLAP"); }
function initializePivotTable(strDataMember) { // Purpose: Call Web Service method to initialize an empty PivotTable var iCallID = service.svcOLAP.callService(oninitializePivotTableResult, 'InitializePivotTableXML', strDataMember); }
function oninitializePivotTableResult(result) { // Purpose: This function handles the wsOLAP.InitializePivotTableXML() web service result var text = result.value; // result string // Evaluate return result if (!result.error) { if (text.indexOf("<err>") > -1 ) { alert(text); } // Assign the XML to the PivotList XMLData value frm1.PivotTable1.XMLData = text; frm1.ChartSpace1.style.visibility = "hidden"; } else { alert("Unhandled error - " + result.errorDetail.code + " " + result.errorDetail.string); } }
function LoadCustomReport() { // Purpose: Call Web Service method to initialize an empty PivotTable var strCity1 = frm1.sel_city1.options[frm1.sel_city1.selectedIndex].value; var strCity2 = frm1.sel_city2.options[frm1.sel_city2.selectedIndex].value; var iCallID = service.svcOLAP.callService(onLoadCustomReportResult, 'LoadCustomPivotTableReport', strCity1, strCity2); }
function onLoadCustomReportResult(result) { // Purpose: This function handles the wsOLAP.LoadCustomPivotTableReport() web service result var text = result.value; // result string // Evaluate return result if (!result.error) { if (text.indexOf("<err>") > -1 ) { alert(text); } // Assign the XML to the PivotList XMLData value frm1.PivotTable1.XMLData = text; // bind the Chart control to the PivotTable control frm1.ChartSpace1.Clear(); frm1.ChartSpace1.DataSource = frm1.PivotTable1; frm1.ChartSpace1.style.visibility = "visible"; //frm1.ChartSpace1.Charts(0).Type = 50; } else { alert("Unhandled error - " + result.errorDetail.code + " " + result.errorDetail.string); } }
function ApplyCustomGrouping() { // Purpose: Call Web Service method to initialize an empty PivotTable var strReportXMLData = frm1.PivotTable1.XMLData; // The "<" and ">" tags cause errors when sent in the web service request. // Replace with "{" and "}". var pattern = /</ig; strReportXMLData = strReportXMLData.replace(pattern,"{"); pattern = />/ig; strReportXMLData = strReportXMLData.replace(pattern,"}"); var iCallID = service.svcOLAP.callService(onApplyCustomGroupingResult, 'ApplyCustomGrouping', strReportXMLData); }
function onApplyCustomGroupingResult(result) { // Purpose: This function handles the wsOLAP.LoadCustomPivotTableReport() web service result var text = result.value; // result string // Evaluate return result if (!result.error) { if (text.indexOf("<err>") > -1 ) { alert(text); } // Assign the XML to the PivotList XMLData value frm1.PivotTable1.XMLData = text; frm1.ChartSpace1.Clear(); frm1.ChartSpace1.DataSource = frm1.PivotTable1; frm1.ChartSpace1.style.visibility = "visible"; } else { alert("Unhandled error - " + result.errorDetail.code + " " + result.errorDetail.string); } }
function SaveReport() { // Purpose: Call Web Service method to save the custom report var strReportXMLData = frm1.PivotTable1.XMLData; // The "<" and ">" tags cause errors when sent in the web service request. // Replace with "{" and "}". var pattern = /</ig; strReportXMLData = strReportXMLData.replace(pattern,"{"); pattern = />/ig; strReportXMLData = strReportXMLData.replace(pattern,"}"); var iCallID = service.svcOLAP.callService(onSaveReportResult, 'SaveReport', strReportXMLData, 'OLAPReport1.xml'); }
function onSaveReportResult(result) { // Purpose: This function handles the wsOLAP.onSaveReportResult() web service result var text = result.value; // result string // Evaluate return result if (!result.error) { if (text.indexOf("<err>") > -1 ) { alert(text); } else { alert("Report was successfully saved to OLAPReport1.xml."); } } else { alert("Unhandled error - " + result.errorDetail.code + " " + result.errorDetail.string); } }
function LoadSavedReport() { // Purpose: Call Web Service method load the saved report var iCallID = service.svcOLAP.callService(onLoadSavedReportResult, 'LoadSavedReport', 'OLAPReport1.xml'); }
function onLoadSavedReportResult(result) { // Purpose: This function handles the wsOLAP.onLoadSavedReportResult() web service result var text = result.value; // result string // Evaluate return result if (!result.error) { if (text.indexOf("<err>") > -1 ) { alert(text); } // Assign the XML to the PivotList XMLData value frm1.PivotTable1.XMLData = text; frm1.ChartSpace1.Clear(); frm1.ChartSpace1.DataSource = frm1.PivotTable1; frm1.ChartSpace1.style.visibility = "visible"; } else { alert("Unhandled error - " + result.errorDetail.code + " " + result.errorDetail.string); } } </script>
http://www.webreference.com/js/column97/column97.zip
把htc放在同一目录下,http://www.xemantex.com/webservice.htc
<HTML>
<HEAD>
<LINK href="baseStyle.css" type="text/css" rel="stylesheet">
<title>Web Services - Create and Consume Demo</title>
<SCRIPT language="JavaScript">
function initWebHTC()
{
//init and create short-cut name for web service
dNtWbSvc.useService("http://www.xemantex.com/consumeDnTWebSvc.asmx?WSDL","dNtSvc");
var iCallID;
if (dNtWbSvc.dNtSvc)
{
document.getElementById("lblDateTime").innerHTML="正在加载..."
iCallID= dNtWbSvc.dNtSvc.callService(gtDnTRslt,"currDateTime");
}
}
function gtDnTRslt(result)
{
//if an error then get error details
if(result.error)
{
//Pull error info from 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
document.getElementById("lblDateTime").innerHTML="Error: " + xfaultcode + " ; " + xfaultstring + " ; " + xfaultsoap;
}
else
{
//alert(result.value);
document.getElementById("lblDateTime").innerHTML=result.value;
//clear any selection
var sRng;
sRng = document.selection.createRange();
sRng.execCommand("unselect");
}
}
</SCRIPT>
</HEAD>
<body onload="initWebHTC();">
<DIV id="dNtWbSvc" style="BEHAVIOR: url(webservice.htc)"></DIV>
<span id="lblDateTime" style="background-color:#99EEDD;height:36px;width:581px;">Date and time will be displayed here.</span></td>
</body>
</HTML>
<title>WebForm1</title>
<meta content="Microsoft Visual Studio .NET 7.1" name="GENERATOR">
<meta content="Visual Basic .NET 7.1" name="CODE_LANGUAGE">
<meta content="JavaScript" name="vs_defaultClientScript">
<meta content="http://schemas.microsoft.com/intellisense/ie5" name="vs_targetSchema">
<LINK href="Styles.css" type="text/css" rel="stylesheet">
<!--#include file=include\olap.js -->
</HEAD>
<body onload="InitializePage()" MS_POSITIONING="GridLayout">
<script language="javascript" event="Query" for="PivotTable1">
{
var sLog = document.Form1.Text1.value + "";
document.Form1.Text1.value = "Query Event Fired. " + sLog;
}
</script>
<script language="vbscript">
Sub PivotTable1_CommandExecute(Command, Succeeded)
Dim ptConstants
Set ptConstants = document.Form1.PivotTable1.Constants ' Check to see if the PivotTable list has been refreshed.
If Command = ptConstants.plCommandRefresh Then
' Write the current data and time to the text box.
document.Form1.Text1.value = vbCrLf & "PivotTable Last Refreshed on " & Date & " at " & Time & vbCrLf & document.Form1.Text1.value
End If
End Sub
</script>附js文件
<script id="iq_olap" language="javascript">
var frm1;
var service; // Page initialization code, called from Body onLoad event handler
function InitializePage() {
service = document.getElementById("service");
// Set page-level variables
frm1 = document.forms[0];
// Create an instance of the web service and call it svcOlap
service.useService("/services/wsOLAP.asmx?WSDL","svcOLAP");
}
function initializePivotTable(strDataMember) {
// Purpose: Call Web Service method to initialize an empty PivotTable
var iCallID = service.svcOLAP.callService(oninitializePivotTableResult, 'InitializePivotTableXML', strDataMember);
}
function oninitializePivotTableResult(result) {
// Purpose: This function handles the wsOLAP.InitializePivotTableXML() web service result
var text = result.value; // result string
// Evaluate return result
if (!result.error) {
if (text.indexOf("<err>") > -1 ) {
alert(text);
}
// Assign the XML to the PivotList XMLData value
frm1.PivotTable1.XMLData = text;
frm1.ChartSpace1.style.visibility = "hidden";
}
else {
alert("Unhandled error - " + result.errorDetail.code + " " + result.errorDetail.string);
}
}
function LoadCustomReport() {
// Purpose: Call Web Service method to initialize an empty PivotTable
var strCity1 = frm1.sel_city1.options[frm1.sel_city1.selectedIndex].value;
var strCity2 = frm1.sel_city2.options[frm1.sel_city2.selectedIndex].value;
var iCallID = service.svcOLAP.callService(onLoadCustomReportResult, 'LoadCustomPivotTableReport', strCity1, strCity2);
}
function onLoadCustomReportResult(result) {
// Purpose: This function handles the wsOLAP.LoadCustomPivotTableReport() web service result
var text = result.value; // result string
// Evaluate return result
if (!result.error) {
if (text.indexOf("<err>") > -1 ) {
alert(text);
}
// Assign the XML to the PivotList XMLData value
frm1.PivotTable1.XMLData = text;
// bind the Chart control to the PivotTable control
frm1.ChartSpace1.Clear();
frm1.ChartSpace1.DataSource = frm1.PivotTable1;
frm1.ChartSpace1.style.visibility = "visible";
//frm1.ChartSpace1.Charts(0).Type = 50;
}
else {
alert("Unhandled error - " + result.errorDetail.code + " " + result.errorDetail.string);
}
}
function ApplyCustomGrouping() {
// Purpose: Call Web Service method to initialize an empty PivotTable
var strReportXMLData = frm1.PivotTable1.XMLData; // The "<" and ">" tags cause errors when sent in the web service request.
// Replace with "{" and "}".
var pattern = /</ig;
strReportXMLData = strReportXMLData.replace(pattern,"{");
pattern = />/ig;
strReportXMLData = strReportXMLData.replace(pattern,"}"); var iCallID = service.svcOLAP.callService(onApplyCustomGroupingResult, 'ApplyCustomGrouping', strReportXMLData);
}
function onApplyCustomGroupingResult(result) {
// Purpose: This function handles the wsOLAP.LoadCustomPivotTableReport() web service result
var text = result.value; // result string
// Evaluate return result
if (!result.error) {
if (text.indexOf("<err>") > -1 ) {
alert(text);
}
// Assign the XML to the PivotList XMLData value
frm1.PivotTable1.XMLData = text;
frm1.ChartSpace1.Clear();
frm1.ChartSpace1.DataSource = frm1.PivotTable1;
frm1.ChartSpace1.style.visibility = "visible";
}
else {
alert("Unhandled error - " + result.errorDetail.code + " " + result.errorDetail.string);
}
}
function SaveReport() {
// Purpose: Call Web Service method to save the custom report
var strReportXMLData = frm1.PivotTable1.XMLData; // The "<" and ">" tags cause errors when sent in the web service request.
// Replace with "{" and "}".
var pattern = /</ig;
strReportXMLData = strReportXMLData.replace(pattern,"{");
pattern = />/ig;
strReportXMLData = strReportXMLData.replace(pattern,"}"); var iCallID = service.svcOLAP.callService(onSaveReportResult, 'SaveReport', strReportXMLData, 'OLAPReport1.xml');
}
function onSaveReportResult(result) {
// Purpose: This function handles the wsOLAP.onSaveReportResult() web service result
var text = result.value; // result string
// Evaluate return result
if (!result.error) {
if (text.indexOf("<err>") > -1 ) {
alert(text);
}
else
{
alert("Report was successfully saved to OLAPReport1.xml.");
}
}
else {
alert("Unhandled error - " + result.errorDetail.code + " " + result.errorDetail.string);
}
}
function LoadSavedReport() {
// Purpose: Call Web Service method load the saved report var iCallID = service.svcOLAP.callService(onLoadSavedReportResult, 'LoadSavedReport', 'OLAPReport1.xml');
}
function onLoadSavedReportResult(result) {
// Purpose: This function handles the wsOLAP.onLoadSavedReportResult() web service result
var text = result.value; // result string
// Evaluate return result
if (!result.error) {
if (text.indexOf("<err>") > -1 ) {
alert(text);
}
// Assign the XML to the PivotList XMLData value
frm1.PivotTable1.XMLData = text;
frm1.ChartSpace1.Clear();
frm1.ChartSpace1.DataSource = frm1.PivotTable1;
frm1.ChartSpace1.style.visibility = "visible";
}
else {
alert("Unhandled error - " + result.errorDetail.code + " " + result.errorDetail.string);
}
}
</script>