using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Diagnostics;
using System.Web;
using System.Web.Services;
using System.Data.OleDb;
using System.Web.UI;
using System.Web.UI.HtmlControls;
namespace Service
{
/// <summary>
/// Service 的摘要说明。
/// </summary>
public class Service : System.Web.Services.WebService
{
public string ConnectionString;
public OleDbConnection Conn;
// public Int32 RecordCount;
public Service()
{
//CODEGEN: 该调用是 ASP.NET Web 服务设计器所必需的
InitializeComponent();
string ConnectionString;
ConnectionString="PROVIDER=SQLOLEDB;Data Source=GISWEB;Initial Catalog=JYJD;User ID=sa;Password=;";
Conn = new OleDbConnection(ConnectionString);
}
[WebMethod(Description="")]
public DataSet GetUserList(int userid)
{
// int i;
OleDbCommand MyCommand = new OleDbCommand("p_LoadUser",Conn);
MyCommand.CommandType = CommandType.StoredProcedure;
OleDbParameter MyPara;
MyPara = MyCommand.Parameters.Add("@userid", SqlDbType.Int);
MyCommand.Parameters["@userid"].Value = userid;
MyPara = MyCommand.Parameters.Add("@msgcount", SqlDbType.Int);
MyPara.Direction = ParameterDirection.Output;
// OleDbDataReader DbCommand = MyCommand.ExecuteReader();
OleDbDataAdapter DbCommand = new OleDbDataAdapter();
DbCommand.SelectCommand = MyCommand;
// RecordCount = (Int32)MyCommand.Parameters["@msgcount"].Value;
DataSet ds = new DataSet();
DbCommand.Fill(ds,"table");
return ds;
// OleDbDataAdapter MyCommand = new OleDbDataAdapter("exec loaduser "+userid,Conn);
// DataSet ds = new DataSet();
// MyCommand.Fill(ds,"table");
// return ds;
}
客户端调用
<html>
<head>
<script language="JavaScript">
var iCallID;
var service_MsgXML = new ActiveXObject("MSXML.DOMDocument");
function init()
{
service.useService("http://gengw/jyjd/service/service.asmx?WSDL","service");
iCallID = service.service.callService("GetUserList",7);
}
</script>
</head>
<body onload="init()">
<div id="service" style="behavior:url(http://gengw/chat/webservice.htc)" onresult="onWSresult()">
</div>
<SCRIPT language="JavaScript1.2">
function onWSresult()
{
if((event.result.error)&&(iCallID==event.result.id))
{
var xfaultcode = event.result.errorDetail.code;
var xfaultstring = event.result.errorDetail.string;
var xfaultsoap = event.result.errorDetail.raw;
alert(xfaultstring);
// Add code to output error information here
}
else
{
var xmlResult = event.result.raw.xml;
// var result = event.result.value;
// alert(result);
if (xmlResult != "" && xmlResult != null)
{
using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Diagnostics;
using System.Web;
using System.Web.Services;
using System.Web.Services.Protocols;
namespace PCSWebSrv3
{
/// <summary>
/// Summary description for Service1.
/// </summary>
public class Service1 : System.Web.Services.WebService
{
public AuthenticationToken AuthenticationTokenHeader;
public Service1()
{
//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