xml Web Service 用途

itliyi 2009-04-15 08:42:12
小弟我了解xml,webservice,但用的话就只知道xml绑定那些控件数据源之类低级的层次了,然后就是Schema,DTD基础,哪位高手告诉我它们最大的用途是什么,最好带学习的网址或资料,感激。。。
...全文
231 8 打赏 收藏 转发到动态 举报
写回复
用AI写文章
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
takako_mu 2009-04-15
  • 打赏
  • 举报
回复
6樓的JS更正如下:

var pagesize=5;//一頁多少條,for分頁
var pageCurrentCount;//第幾頁,for分頁
var pageTotalCount;//總條數,for分頁

function pageLoad(sender,args)
{
if(!args._isPartialLoad)
{
Sys.WebForms.PageRequestManager.getInstance().add_beginRequest(beginRequestHandler);
Sys.WebForms.PageRequestManager.getInstance().add_endRequest(endRequestHandler);
pageCurrentCount=1;
GetPageTotalCount(pagesize);
}
GetPublicElement(1,"userName");//flag1用來區別是現有的Select控件,還是編輯時候Create的Select控件
GetPublicElement(1,"itemName");
Search(pagesize,pageCurrentCount);
document.getElementById("lab_CurrentPage").innerText="1";
}


/*--動態的圖片可讓界面更形象,也能彌補AJAX刷新不明顯的缺點----------------------------------------------------------*/
function beginRequestHandler(sender,args)
{
$get("displayImage").style.display="block";
}

function endRequestHandler(sender,args)
{
$get("displayImage").style.display="none";
}
/*--動態的圖片可讓界面更形象,也能彌補AJAX刷新不明顯的缺點----------------------------------------------------------*/




/*--相當于GridViewBind()-------------------------------------------------------------------------------------------*/
function Search(pagesize,pageCurrentCount)
{
var UserName=$get("optSelectUserName").value;
var Project=$get("optSelectProject").value;
GetData(pagesize,pageCurrentCount,UserName,Project);
return false;
}

function GetData(pagesize,pageCurrentCount,userName, project)
{
$get("displayImage").style.display="block";
var UserName=userName;
var Project=project;
WebService_AJAXGridView.GetData(pagesize,pageCurrentCount,UserName, Project, SucceededCallback, FailedCallback,"XmlDocument");
}

function SucceededCallback(result, userContext, methodName)
{
if (userContext == "XmlDocument")
{
UpdateTable(result);
}
$get("displayImage").style.display="none";
//document.getElementById("lab_TotalPage").innerText=
}

function FailedCallback(error)
{
// Display the error.
var stackTrace=error.get_stackTrace();
var message= error.get_message();
var statusCode=error.get_statusCode();
var exceptionType=error.get_exceptionType();
var timeout=error.get_timedOut();

var errstr="推疊追蹤: "+ stackTrace+"\n";
errstr+="服務錯誤:"+ message+"\n";
errstr+="狀態碼:"+ statusCode+"\n";
errstr+="例外類型:"+ exceptionType+"\n";
errstr+="逾時:"+ timeout+"\n";
errstr+="請關掉IE, 重新進入 !!";
alert(errstr);

$get("displayImage").style.display="none";
}
/*--相當于GridViewBind()-------------------------------------------------------------------------------------------*/




/*--Select控件的綁定-----------------------------------------------------------------------------------------------*/
function GetPublicElement(flag1,Type)//flag1用來區別是現有的Select控件,還是編輯時候Create的Select控件
{
WebService_AJAXGridView.SelectTypeBind(flag1,Type,SucceededGetPublicElement,FailedGetPublicElement);
}

function SucceededGetPublicElement(reusltText)
{
//alert(reusltText);
var getPublicElementResult;
getPublicElementResult=reusltText;
var str=new Array();
str=getPublicElementResult.split(',');
var type=str[0];
var count=parseInt(str[1]);
var flag1=parseInt(str[2]);
if(flag1==1)
{
switch(type)
{
case "userName":
var objSelect=document.getElementById("optSelectUserName");
for(var i=3;i<=count+2;i++)
{
objSelect.options[i-2]=new Option(str[i],str[i]);
}
break;
case "itemName":
var objSelect=document.getElementById("optSelectProject");
for(var i=3;i<=count+2;i++)
{
objSelect.options[i-2]=new Option(str[i],str[i]);
}
break;
default:
break;
}
}
if(flag1==2)
{
for(var i=3;i<=count+2;i++)
{
innerSelect.options[i-3] = new Option(str[i],str[i]);
}
innerSelect.value=currentCell.innerHTML;
innerSelect.onblur=last1;
currentCell.innerHTML="";
currentCell.appendChild(innerSelect);
innerSelect.focus();
}
}

function FailedGetPublicElement(error)
{
var stackTrace=error.get_stackTrace();
var message= error.get_message();
var statusCode=error.get_statusCode();
var exceptionType=error.get_exceptionType();
var timeout=error.get_timedOut();

var errstr="推疊追蹤: "+ stackTrace+"\n";
errstr+="服務錯誤:"+ message+"\n";
errstr+="狀態碼:"+ statusCode+"\n";
errstr+="例外類型:"+ exceptionType+"\n";
errstr+="逾時:"+ timeout+"\n";
errstr+="請關掉IE, 重新進入 !!";
alert(errstr);

$get("displayImage").style.display="none";
}
/*--Select控件的綁定-----------------------------------------------------------------------------------------------*/

takako_mu 2009-04-15
  • 打赏
  • 举报
回复

--DB如下
No Project Item Code Description Percent Status Start Date Due Date Owner NeedTime
---- ------------------- ---- -------------------------------------------------- -------------------------------
12 生日系統 系統 Delete dd 50 Open 2008-08-21 2008-08-25 Takako 4H
takako_mu 2009-04-15
  • 打赏
  • 举报
回复

using System;
using System.Data;
using System.Xml;
using System.Text;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Services;
using System.Web.Services.Protocols;
using System.Web.Script.Services;
using System.Web.Script.Serialization;
using System.Web.Security;
using System.Xml.Linq;
using System.Data.Sql;
using System.Data.SqlClient;



/// <summary>
/// WebService_AJAXGridView 的摘要描述
/// </summary>
[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
// 若要允許使用 ASP.NET AJAX 從指令碼呼叫此 Web 服務,請取消註解下一行。
[System.Web.Script.Services.ScriptService]
public class WebService_AJAXGridView : System.Web.Services.WebService {

public WebService_AJAXGridView () {

//如果使用設計的元件,請取消註解下行程式碼
//InitializeComponent();
}

[WebMethod]
public string HelloWorld() {
return "Hello World";
}

//Create By Takako_Yang,at 2008/12/04
[WebMethod(Description = "My AJAX Gridview Data Select", EnableSession = true)]
[ScriptMethod(ResponseFormat = ResponseFormat.Xml)]
public XmlDocument GetData(int pagesize,int pageCurrentCount,string userName, string project)
{
DailyWorkFactory myDailyWorkFactory = new DailyWorkFactory();
DataTable dt = myDailyWorkFactory.GetDailyWork(0, 1,pagesize,pageCurrentCount, userName, project, "");//flag1用來判斷Select來源自現有的,還是編輯時Create的新的
StringBuilder sb = new StringBuilder();
sb.Append("<AJAXSet>");
//select [No],Project,Item,Code,[Description (purpose/value)],
//Status,[%],[Start Date],[Due Date],Owner,[Day/Hour] from daily_work
foreach (DataRow myDataRow in dt.Rows)
{
string No = myDataRow[0].ToString();
string Project1 = myDataRow[1].ToString();
string Item = myDataRow[2].ToString();
string Code = myDataRow[3].ToString();
string Desciption = myDataRow[4].ToString();
string Status = myDataRow[5].ToString();
string Percent = myDataRow[6].ToString();
string StartDate = (Convert.ToDateTime(myDataRow[7])).ToString("yyyy/MM/dd");
string DueDate = (Convert.ToDateTime(myDataRow[8])).ToString("yyyy/MM/dd");
string Owner = myDataRow[9].ToString();
string NeedTime = myDataRow[10].ToString();
sb.Append("<AJAXData>");
sb.Append("<P1>").Append(No).Append("</P1>");
sb.Append("<P2>").Append(Project1).Append("</P2>");
sb.Append("<P3>").Append(Item).Append("</P3>");
sb.Append("<P4>").Append(Code).Append("</P4>");
sb.Append("<P5>").Append(Desciption).Append("</P5>");
sb.Append("<P6>").Append(Status).Append("</P6>");
sb.Append("<P7>").Append(Percent).Append("</P7>");
sb.Append("<P8>").Append(StartDate).Append("</P8>");
sb.Append("<P9>").Append(DueDate).Append("</P9>");
sb.Append("<P10>").Append(Owner).Append("</P10>");
sb.Append("<P11>").Append(NeedTime).Append("</P11>");
sb.Append("</AJAXData>");
}
sb.Append("</AJAXSet>");
XmlDocument xmlDoc = new XmlDocument();
xmlDoc.LoadXml(sb.ToString());
return xmlDoc;
}


[WebMethod(Description = "My AJAX Gridview PageTotalCount", EnableSession = true)]
public int GetPageTotalCount(int pagesize,string userName,string project)
{
DailyWorkFactory myDailyWorkFactory = new DailyWorkFactory();
int count = myDailyWorkFactory.GetPageTotalCount(pagesize, userName, project);
return count;
}


[WebMethod(Description = "My AJAX Gridview Edit", EnableSession = true)]
public string EditData(string id, string fieldname, string value1)
{
DailyWorkFactory myDailyWorkFactory = new DailyWorkFactory();
string check = myDailyWorkFactory.DailyWorkEdit(id, fieldname, value1);
return check;
}


[WebMethod(Description = "Select控件 Bind", EnableSession = true)]
public string SelectTypeBind(int flag1,string type)
{
DailyWorkFactory myDailyWorkFactory = new DailyWorkFactory();
string temp = myDailyWorkFactory.TypeSelect(flag1,2, type);
return temp;
}
}

takako_mu 2009-04-15
  • 打赏
  • 举报
回复

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="AJAXGridView.aspx.cs" Inherits="AJAXGridView" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>未命名頁面</title>
<link href="Table.css" rel="stylesheet" type="text/css" />
</head>
<body>
<form id="form1" runat="server">
<asp:ScriptManager ID="ScriptManager1" runat="server" ScriptMode="Release">
<Scripts>
<asp:ScriptReference Path="~/AJAXGrid.js" />
</Scripts>
<Services>
<asp:ServiceReference Path="~/WebService_AJAXGridView.asmx" />
</Services>
</asp:ScriptManager>

<div style="display:none"><asp:Button ID="Button1" runat="server" Text="Search" OnClientClick="return Search()"/></div>
<table>
<tr><td>
<select id="optSelectUserName" onchange= "SelectChange();">
<option>-請選擇-</option>
</select>
</td><td>
<select id="optSelectProject" onchange= "SelectChange();">
<option>-請選擇-</option>
</select>
</td>
</tr>
</table>
<div id="displayImage" style="position: absolute; left: 300px; top: 300px; z-index: 105; display:none">
<asp:Image ID="Image2" runat="server" ImageUrl="~/images/ajax-loader1.gif"
meta:resourcekey="Image2Resource1" />
</div>
<div id="__AJAX_GridView1__div" ondblclick="return editCell()"></div>
<div id="div_btnList">
<span id="span_FirstPage"><input id="btn_FirstPage" value="首頁" type="button" onclick="return btn_FirstPage_onclick()" /></span>
<span id="span_NextPage"><input id="btn_PervPage" value="上一頁" type="button" onclick="return btn_PervPage_onclick()" /></span>
<span id="span_LastPage"><input id="btn_NextPage" value="下一頁" type="button" onclick="return btn_NextPage_onclick()" /></span>
<span id="span_CurrentPage"><input id="btn_LastPage" value="尾頁" type="button" onclick="return btn_LastPage_onclick()" /></span>
</div>
<div id="div_Page">
<span id="span_PervPage"><asp:Label ID="lab_CurrentPage" runat="server" Text="Label"></asp:Label></span>
<span id="span_xiexian">/</span>
<span id="span_TotalPage"><asp:Label ID="lab_TotalPage" runat="server" Text="Label"></asp:Label></span>
</div>
</form>
</body>
</html>
takako_mu 2009-04-15
  • 打赏
  • 举报
回复

using System;
using System.Data;
using System.Xml;
using System.Text;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Services;
using System.Web.Services.Protocols;
using System.Web.Script.Services;
using System.Web.Script.Serialization;
using System.Web.Security;
using System.Xml.Linq;
using System.Data.Sql;
using System.Data.SqlClient;



/// <summary>
/// WebService_AJAXGridView 的摘要描述
/// </summary>
[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
// 若要允許使用 ASP.NET AJAX 從指令碼呼叫此 Web 服務,請取消註解下一行。
[System.Web.Script.Services.ScriptService]
public class WebService_AJAXGridView : System.Web.Services.WebService {

public WebService_AJAXGridView () {

//如果使用設計的元件,請取消註解下行程式碼
//InitializeComponent();
}

[WebMethod]
public string HelloWorld() {
return "Hello World";
}

//Create By Takako_Yang,at 2008/12/04
[WebMethod(Description = "My AJAX Gridview Data Select", EnableSession = true)]
[ScriptMethod(ResponseFormat = ResponseFormat.Xml)]
public XmlDocument GetData(int pagesize,int pageCurrentCount,string userName, string project)
{
DailyWorkFactory myDailyWorkFactory = new DailyWorkFactory();
DataTable dt = myDailyWorkFactory.GetDailyWork(0, 1,pagesize,pageCurrentCount, userName, project, "");//flag1用來判斷Select來源自現有的,還是編輯時Create的新的
StringBuilder sb = new StringBuilder();
sb.Append("<AJAXSet>");
//select [No],Project,Item,Code,[Description (purpose/value)],
//Status,[%],[Start Date],[Due Date],Owner,[Day/Hour] from daily_work
foreach (DataRow myDataRow in dt.Rows)
{
string No = myDataRow[0].ToString();
string Project1 = myDataRow[1].ToString();
string Item = myDataRow[2].ToString();
string Code = myDataRow[3].ToString();
string Desciption = myDataRow[4].ToString();
string Status = myDataRow[5].ToString();
string Percent = myDataRow[6].ToString();
string StartDate = (Convert.ToDateTime(myDataRow[7])).ToString("yyyy/MM/dd");
string DueDate = (Convert.ToDateTime(myDataRow[8])).ToString("yyyy/MM/dd");
string Owner = myDataRow[9].ToString();
string NeedTime = myDataRow[10].ToString();
sb.Append("<AJAXData>");
sb.Append("<P1>").Append(No).Append("</P1>");
sb.Append("<P2>").Append(Project1).Append("</P2>");
sb.Append("<P3>").Append(Item).Append("</P3>");
sb.Append("<P4>").Append(Code).Append("</P4>");
sb.Append("<P5>").Append(Desciption).Append("</P5>");
sb.Append("<P6>").Append(Status).Append("</P6>");
sb.Append("<P7>").Append(Percent).Append("</P7>");
sb.Append("<P8>").Append(StartDate).Append("</P8>");
sb.Append("<P9>").Append(DueDate).Append("</P9>");
sb.Append("<P10>").Append(Owner).Append("</P10>");
sb.Append("<P11>").Append(NeedTime).Append("</P11>");
sb.Append("</AJAXData>");
}
sb.Append("</AJAXSet>");
XmlDocument xmlDoc = new XmlDocument();
xmlDoc.LoadXml(sb.ToString());
return xmlDoc;
}


[WebMethod(Description = "My AJAX Gridview PageTotalCount", EnableSession = true)]
public int GetPageTotalCount(int pagesize,string userName,string project)
{
DailyWorkFactory myDailyWorkFactory = new DailyWorkFactory();
int count = myDailyWorkFactory.GetPageTotalCount(pagesize, userName, project);
return count;
}


[WebMethod(Description = "My AJAX Gridview Edit", EnableSession = true)]
public string EditData(string id, string fieldname, string value1)
{
DailyWorkFactory myDailyWorkFactory = new DailyWorkFactory();
string check = myDailyWorkFactory.DailyWorkEdit(id, fieldname, value1);
return check;
}


[WebMethod(Description = "Select控件 Bind", EnableSession = true)]
public string SelectTypeBind(int flag1,string type)
{
DailyWorkFactory myDailyWorkFactory = new DailyWorkFactory();
string temp = myDailyWorkFactory.TypeSelect(flag1,2, type);
return temp;
}
}
itliyi 2009-04-15
  • 打赏
  • 举报
回复
2楼能教我吗?table代替gridview
takako_mu 2009-04-15
  • 打赏
  • 举报
回复
我只會用JS+XML+WebService做一些簡單的ajax,如table代替gridview.
moonshineidolon 2009-04-15
  • 打赏
  • 举报
回复
xml用户传输数据,保持数据。

62,267

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术交流专区
javascript云原生 企业社区
社区管理员
  • ASP.NET
  • .Net开发者社区
  • R小R
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

.NET 社区是一个围绕开源 .NET 的开放、热情、创新、包容的技术社区。社区致力于为广大 .NET 爱好者提供一个良好的知识共享、协同互助的 .NET 技术交流环境。我们尊重不同意见,支持健康理性的辩论和互动,反对歧视和攻击。

希望和大家一起共同营造一个活跃、友好的社区氛围。

试试用AI创作助手写篇文章吧