Tutorials to .com

Tutorials to .com » Dotnet » Webservice » Integrity of the site to share data between the WebService

Integrity of the site to share data between the WebService

Print View , by: iSee ,Total views: 13 ,Word Count: 739 ,Date: Wed, 20 May 2009 Time: 11:32 AM

Integrity of the site to share data between the WebService

I remember that if a netizen asked how in a few sites on the shared database of resources between the two computers I have successfully tested my code is to provide such a reference database in the site database server, there is a data Table NoteBoard
Field contains the ID (ID), Title (title), NoterName (message name), NoteTime (message time)
How can this site b to obtain the records of this data sheet.
In a visit to a station database on the definition of the webservice file MyViewDBService.asmx
<% @ WebService Language = "C #" Class = "ViewDBService"%>
using System;
using System.Data;
using System.Data.OleDb;
using System.Web.Services;
public class ViewDBService: WebService
(
[WebMethod]
public DataSet ViewDB ()
(
string connStr = "Provider = Microsoft.Jet.OLEDB.4.0; Data Source = E: \ \ WmjDB.mdb";
OleDbConnection conn = new OleDbConnection (connStr);
string sqls = "select ID, Title, NoterName, NoteTime from NoteBoard order by id";
OleDbDataAdapter adapter = new OleDbDataAdapter ();
adapter.SelectCommand = new OleDbCommand (sqls, conn);
DataSet dataSet = new DataSet ();
adapter.Fill (dataSet, "NoteBoard");
conn.Close ();
return dataSet;
)
)
////////////////////////////////////////////////// /////////////////////////////
The assumption that the webservice in http://www.a.com/MyViewDBService.asmx
Customer care as the client can use the site b
wsdl / l: cs / n: DBService / out: ViewDBServiceClient.cs http://www.w.com/MyViewDBService.asmx
Generating client files ViewDBServiceClient.cs
Using csc / t: library / out: ViewDBServiceClient.dll ViewDBServiceClient.cs compiled dll
Page document prepared by the client index.aspx
<% @ Page language = "C #" Codebehind = "index.aspx.cs" AutoEventWireup = "false" Inherits = "Wmj.ViewDB"%>
<html>
<head>
<title> my message board </ title>
</ head>
<body>
<form runat="server">
<center>
<asp: DataGrid id = "dataGrid1" ItemStyle-BackColor = "# AAAADD" AutoGenerateColumns = "false"
AlternatingItemStyle-BackColor = "# CCCCFF" HeaderStyle-BackColor = "# 000000"
HeaderStyle-HorizontalAlign = "Center"
HeaderStyle-ForeColor = "# FFFFFF" PagerStyle-Mode = "NumericPages"
AllowPaging = "true" PageSize = "4" Font-Size = "10pt" runat = "server">
<columns>
<asp:BoundColumn HeaderText="" DataField="ID"/>
<asp:BoundColumn HeaderText="" DataField="Title"/>
<asp:BoundColumn HeaderText="" DataField="NoterName"/>
<asp:BoundColumn HeaderText="" DataField="NoteTime" DataFormatString="{0:dd/MM/yyyy}"/>
</ columns>
</ asp: DataGrid>
<asp:Label id="label1" runat="server"/>
</ center>
</ form>
</ body>
</ html>
The preparation of client files codebehind index.aspx.cs
////////////////////////////////////////////////// //////////////////
using System;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.OleDb;
using DBService; / / introduced in the name of the client space
namespace Wmj
(
public class ViewDB: Page
(
protected DataGrid dataGrid1;
public ViewDB ()
(
this.Init + = new EventHandler (this.Page_Init);
)
public void Page_Init (object sender, EventArgs e)
(
this.Load + = new EventHandler (this.Page_Load);
this.dataGrid1.PageIndexChanged + = new
DataGridPageChangedEventHandler (this.DataGrid1_PageIndexChanged);
)
public void Page_Load (object sender, EventArgs e)
(
ViewDBService viewDBService = new ViewDBService ();
/ / Use the webservice
dataGrid1.DataSource = viewDBService.ViewDB (). Tables [ "NoteBoard"]. DefaultView;
if (! Page.IsPostBack)
(
dataGrid1.CurrentPageIndex = 0;
dataGrid1.DataBind ();
)

)
public void DataGrid1_PageIndexChanged (object sender, DataGridPageChangedEventArgs e)
(
dataGrid1.CurrentPageIndex = e.NewPageIndex;
dataGrid1.DataBind ();
)
)
)



Author: Love.NET
Source: Love.NET
Contributor: Jiang epitaxial


.Net WebService Articles


Can't Find What You're Looking For?


Rating: Not yet rated

Comments

No comments posted.