using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Diagnostics;
using System.Web;
using System.Web.Services;
using Microsoft.Web.UI.WebControls ;namespace public_nntc
{
/// <summary>
/// Summary description for ShortMessage.
/// </summary>
public class ShortMessage : System.Web.Services.WebService
{
public ShortMessage()
{
//CODEGEN: This call is required by the ASP.NET Web Services Designer
InitializeComponent();
} #region Component Designer generated code

//Required by the Web Services Designer 
private IContainer components = null;

/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
} /// <summary>
/// Clean up any resources being used.
/// </summary>
protected override void Dispose( bool disposing )
{
if(disposing && components != null)
{
components.Dispose();
}
base.Dispose(disposing);
}

#endregion // WEB SERVICE EXAMPLE
// The HelloWorld() example service returns the string Hello World
// To build, uncomment the following lines then save and build the project
// To test this web service, press F5 [WebMethod]
public string HelloWorld()
{
return "Hello World";
}
}

解决方案 »

  1.   

    <%@ Page language="c#" Codebehind="LookSql.aspx.cs" AutoEventWireup="false" Inherits="public_nntc.LookSql" %>
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >
    <HTML>
    <HEAD>
    <title>LookSql</title>
    <meta content="Microsoft Visual Studio 7.0" name="GENERATOR">
    <meta content="C#" name="CODE_LANGUAGE">
    <meta content="JavaScript" name="vs_defaultClientScript">
    <meta content="http://schemas.microsoft.com/intellisense/ie5" name="vs_targetSchema">
    <SCRIPT language="JavaScript">  var enable = true
    var TimerID ;

    function init() 

    //调用Web服务            调用的web服务的URI                   服务的实例名 
    service.useService("../webservice9/ShortMessage.asmx?WSDL","wmjService"); 
    TimerID = window.setInterval( "fun();", 5000 )
    service.wmjService.callService( ShowDebug,"EnalbeGetSql", enable);
    }  function fun() 

    arr = new Array( "select", "update" )

    //      服务实例名              结果显示方法   调用的WebMethod名 参数列表 
    service.wmjService.callService(showCode,"GetSqlCommand", arr);  
    if( enable == false )
    window.clearInterval( TimerID )
    }  function showCode(result)  
    {  
    var line = '\r\n```````````````````````````````````````````````````````````````````````````````````````````````\r\n'
    arr = new Array()
    arr = result.value
    for( i = 0 ; i < arr.length ; i++ )
    LookSql.SqlCommand.value = LookSql.SqlCommand.value + line + arr[ i ];  
    }  

    function Stop()
    {
    if( enable )
    {
    LookSql.stop.value = "运行" 
    TimerID = window.setInterval( "fun();", 5000 )
    }
    else
    LookSql.stop.value = "暂停" 

    enable = !enable
    service.wmjService.callService( ShowDebug,"EnalbeGetSql", enable);

    }

    function ShowDebug( result )
    {
    alert( '是否运行: ' + result.value )
    }

    function unload()
    {
    service.wmjService.callService( ShowDebug,"EnalbeGetSql", false );
    }
    </SCRIPT>
    </HEAD>
    <body onload="init();" onunload="unload();">
    <form id="LookSql" method="post" runat="server">
    <FONT face="宋体">
    <TABLE id="Table1" style="WIDTH: 722px; HEIGHT: 309px" cellSpacing="1" cellPadding="1" width="722" border="1">
    <TR>
    <TD style="HEIGHT: 325px"><TEXTAREA id="SqlCommand" style="WIDTH: 746px; HEIGHT: 391px" name="SqlCommand" rows="24" cols="90"></TEXTAREA></TD>
    </TR>
    <TR>
    <TD>
    <DIV id="service" style="BEHAVIOR: url(../webservice9/webservice.htc)">
    <INPUT id="stop" style="WIDTH: 80px; HEIGHT: 24px" onclick="Stop();" type="button" value="停止" name="stop">
    <INPUT style="WIDTH: 81px; HEIGHT: 24px" onclick="SqlCommand.value=''" type="button" value="清空">
    <INPUT onclick="window.location = 'menu.aspx'" type="button" value="返回导航页"></DIV>
    </TD>
    </TR>
    </TABLE>
    </FONT>
    </form>
    </body>
    </HTML>
      

  2.   

    以下是上述调用的Web服务,也应写在第一个文件中[WebMethod] 
    public string[] GetSqlCommand( string[] arr ) 

    string tmp = "";
    for( int i = 0 ; i < arr.Length ; i++ )
    tmp += "," + arr[ i ] ;

    DataTable dt = 数据库访问.查询SQL语句() ;
    数据库访问.删除SQL语句() ; string[] Command = 字符串处理.DataTable的某列2字符串数组( dt, "语句" ) ;
    for( int i = 0 ; i < Command.Length ; i++ )
    Command[ i ] = Command[ i ].Replace( '"', '\'' ) ;
    return Command ;
    // return new string[]{ "ab" } ;
    }  [WebMethod] 
    public string EnalbeGetSql( bool Enalbe ) 

    数据库访问.删除SQL语句() ;
    Global.IsDebug = Enalbe ;
    return Global.IsDebug.ToString() ;
    }  string 查询语句 ;
    string 字段名称 ;
    [WebMethod] 
    public string TreeViewTest( string index, string name, string code ) 

    string 报表编号 = code;
    字段名称 = name ;
    DataTable dt = 报表查看数据类.取查询语句( 报表编号, 字段名称 ) ;
    查询语句 = (string)dt.Rows[ 0 ]["查询语句"] ;
    int pos = 查询语句.ToLower().IndexOf( "order by" ) ;
    if( pos > 0 )
    查询语句 = 查询语句.Substring( 0, pos ) ; return FindNodeValue( "", index.Substring( 2 ) ) ;
    //return  index + " " + name + " " + code + " " ;
    }