XML Web ServiceData Exchange
The client calls the serverWebServices that contain dataDataset (DS):
Private sub synchronize ()
Dim username as string = "Johns"
Dim blnsuccess as Boolean
'UseXML Web ServiceSynchronize
Cursor. Current = cursors. waitcursor
Dim wsfeedback as new wsfeedback. Feedback
Blnsuccess = wsfeedback. insertfeedback (DS, username)
Cursor. Current = cursors. Default
End sub
Server Side Web Service acceptance Dataset And set XML Directly transfer SQL Server 2000 In the stored procedure SQLXML (English) and Openxml Analysis XML Insert new data into the appropriate table.
<Webmethod ()> _
Public Function insertfeedback (byval ds as dataset, byval username
String) as Boolean
Dim con as new sqlconnection (connectionstring)
Dim cmd as new sqlcommand ("p_feedback_ I", con)
Cmd. commandtype = commandtype. storedprocedure
'Set parameters
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
'Handle, record, and re-throw errors
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 Integer
Declare @ ErrorInteger
/* Create XML document .*/
Exec sp_xml_preparedocument @ IDOC output, @ XML
/* Insert new records */
InsertFeedback
(
Feedbackid,
Plantsection,
Part,
Defectscope,
Scopeid,
Defecttype,
Richink,
Username
)
SelectID,
Plantsection,
Part,
Defectscope,
Scopeid,
Defecttype,
Richink,
@ Username
From openxml (@ IDOC, '/dataset/feedback', 2)
(
IDUniqueidentifier,
PlantsectionInt,
PartInt,
DefectscopeInt,
ScopeidNvarchar (50 ),
DefecttypeInt,
RichinkNvarchar (50)
)
Select @ error = @ Error
If (@ error <> 0)
Begin
Goto errorhandler
End
/* 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