当前位置: 首页 > 图文教程 > 网络编程 > ASP.NET > XML Web Service 数据交换

ASP.NET
调用另外一个同名的重载函数漏掉括号出现的严重问题
DataGrid模板列应用:在DataGrid中用CheckBox控制TextBox的Enabled属性
使用存储过程的一个小例子
.net中xmlhttp下载文件的方法参考
简单的c#文本文件读写
我的C#学习过程 第一天 安装
在数据库中开始一个事务。
用ASP.NETt实现简单的文字水印
C/S系统中三层结构(Com/Com+)的测试成功实现
VB 二进制块读写类模块应用实例,包括一个文件拷贝和一个文件二进制比较的例子。
扫雷程序“布雷”代码(vb)
关于网络连接状态的编程
c#中ref和out参数使用时需要注意的问题
use Assembly to call a method
在VBA中调用AUTOCAD打印文件
在VS.NET的
昨天折腾了一晚上,哪位高手帮我看看!急!
Net是未来的趋势吗?
如何修改自定义Webpart 的标题(downmoon)
[收藏]ASP.Net生成静态HTML页 选择自 coofucoo 的 Blog

ASP.NET 中的 XML Web Service 数据交换


出处:互联网   整理: 软晨网(RuanChen.com)   发布: 2009-11-03   浏览: 51 ::
收藏到网摘: n/a

XML Web Service 数据交换
客户端调用服务器端的 Web 服务并传递包含数据的 DataSet (ds):
Private Sub Synchronize() Dim username As String = "JohnS" Dim blnSuccess As Boolean ' 使用 XML Web Service 进行同步 Cursor.Current = Cursors.WaitCursor Dim wsFeedback As New wsFeedback.feedback blnSuccess = wsFeedback.InsertFeedback(ds, username)
Cursor.Current = Cursors.DefaultEnd Sub
服务器端的 Web 服务接受 DataSet 并将 XML 直接传递到 SQL Server 2000 存储的过程中,该过程使用 SQLXML(英文)和 OPENXML 解析 XML 并将新数据插入适当的表格。
_Public Function InsertFeedback(ByVal ds As DataSet, ByVal username As String) As Boolean Dim con As New SqlConnection(connectionstring) Dim cmd As New SqlCommand("p_Feedback_i", con) cmd.CommandType = CommandType.StoredProcedure
' 设置参数 Dim prmXML As SqlParameter = cmd.Parameters.Add("@XML", SqlDbType.NText) prmXML.Direction = ParameterDirection.Input prmXML.Value = ds.GetXml
Dim prmUsername As SqlParameter = cmd.Parameters.Add("@Username", SqlDbType.NVarChar) prmUsername.Direction = ParameterDirection.Input prmUsername.Value = username

Try con.Open() cmd.ExecuteNonQuery() Catch ex As Exception ' 处理、记录并重掷错误 Throw ex
Finally con.Close() End Try
Return True
End Function
The stored procedure inserts the new data:
CREATE PROCEDURE p_Feedback_i @XML ntext, @Username nvarchar(50)
AS
SET NOCOUNT ON
DECLARE @iDoc integerDECLARE @Error integer
/* Create XML document. */EXEC sp_xml_preparedocument @iDoc OUTPUT, @XML
/* Insert new records */INSERT INTO Feedback ( FeedbackID, PlantSection, Part, DefectScope, ScopeID, DefectType, RichInk, Username )SELECT ID, PlantSection, Part, DefectScope, ScopeID, DefectType, RichInk, @UsernameFROM OPENXML (@iDoc, '/DataSet/Feedback',2) WITH ( ID uniqueidentifier, PlantSection int, Part int, DefectScope int, ScopeID nvarchar(50), DefectType int, RichInk nvarchar(50) )
SELECT @Error = @@ERRORIF (@Error <> 0)BEGIN GOTO ErrorhandlerEND
/* Remove the XML document*/EXEC sp_xml_removedocument @iDoc
RETURN
Errorhandler:
IF NOT @iDoc IS NULL EXEC sp_xml_removedocument @iDoc
RAISERROR (@Error,16,1)
RETURN