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

ASP.NET
如何使用vb6.0来实现中文实名搜索
C#实现Window管道技术
记录下一些关于测试工具NUNIT的链接资料,有兴趣的朋友也可以跳过去看看
编写与.NET属性窗口交互的RAD组件(自序)
asp.net 关于form认证的一般设置:
编写与.NET属性窗口交互的RAD组件(一)
ActiveX控件的打包发布[无证书发布](一)
Visual SourceSafe 6.0 的问题思考
VB报表输出的问题,恳请不吝赐教
证书和签名--试用微软提供的证书测试工具系列
[dotNET]如何利用ConfigurationSettings.AppSettings.GetValues读取配置文件中多个...
使用C#编写DES加密程序的framework
令你的网页速度大大提高
怎样得到一个系统盘的全名,不是字符,是全名,如:本地磁盘(C:)?
r在richtextbox中插入动画/控件
Code: Writing Text to a File (Visual Basic)
算法讨论:哲学家就餐问题
我们所要关注的是什么?
firebird 连接嵌入式版本
从Csharp走到VB.Net(一):MyClass保留字

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


出处:互联网   整理: 软晨网(RuanChen.com)   发布: 2009-11-03   浏览: 58 ::
收藏到网摘: 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