server端:(service1.asmx.cs)
using System;
using System.Text;
using System.Configuration;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Data.SqlClient;
using System.Diagnostics;
using System.Web;
using System.Web.Services;
namespace WebService1
{
/// <summary>
/// Summary description for Service1.
/// </summary>
public class Service1 : System.Web.Services.WebService
{
SqlConnection con;
public Service1()
{
//CODEGEN: This call is required by the ASP.NET Web Services Designer
InitializeComponent();
}
#region Component Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
string dsn = ConfigurationSettings.AppSettings["yitong"];
con=new SqlConnection(dsn);
}
#endregion
/// <summary>
/// Clean up any resources being used.
/// </summary>
protected override void Dispose( bool disposing )
{
}
[WebMethod]
public string fenlei()
{
string str="select distinct substring(code,1,3) as fenlei from jinan ";
SqlCommand cmd=new SqlCommand(str,con);
[WebMethod]
public string haoduan(string q)
{
string str="select distinct substring(code,4,4) as haoduan from jinan where type='"+q+"'";
SqlCommand cmd=new SqlCommand(str,con);
client端(htmlpage1.htm)
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >
<HTML>
<HEAD>
<META NAME="GENERATOR" Content="Microsoft Visual Studio 7.0">
<TITLE></TITLE>
<script id="clientEventHandlersJS" language="javascript">
<!--
var icallid;
var icallid1;
var icallid2;
function window_onload() {
service.useService("/service1.asmx?WSDL","myselect");