Module CustomerXML.wo
1Use cWebService.pkg
2Use DataDict.pkg
3Use Customer.DD
4
5Object oCustXML is a cWebService
6
7 // The main purpose of this sample is to show how data can be passed in and out
8 // as non-specified XML.
9 // When writing your functions, always consider using structs and arrays first. These data
10 // types could represent a simpler solution for the users and fewer lines of code
11 // in your function.
12
13 // psDocumentation provides high level documentation of your web service. Clients using
14 // this service will see and use this documentation.
15 Set psDocumentation to ;
16 ("This uses a web service to return a list of customers and to pass a " +;
17 "list of customers with items marked for delete. It is expected that the" + ;
18 "client using this will know what the format of the XML document must be")
19
20 Set psServiceName to "CustomerXML"
21 Set psServiceURI to "http://tempuri.org/"
22 Set psServiceTitle to "Customer XML Service"
23
24 Object Customer_DD is a Customer_DataDictionary
25 Send DefineAllExtendedFields
26 End_Object // Customer_DD
27
28 Set Main_DD to Customer_DD
29
30 { Published = True }
31 { Description = "Returns an XML document of all customers (Name, Number, State)." }
32 Function CustomerXMLList Returns XmlHandle
33 Integer bOk
34 Handle hoXML hoRoot hoEle hoXML1 hoRoot1
35 Handle hoCustomerDD
36 String sName sNumber sState sNamespace
37
38 Move Customer_dd to hoCustomerDD
39
40 // namespace to use for document
41 Move "http://www.dataaccess.com/Test/CustomerList" to sNameSpace
42
43 // create XML document / Create root node
44 Get Create (RefClass(cXMLDomDocument)) to hoXML
45 // Create the Root element named CustomerList
46 Get CreateDocumentElementNS Of hoXML sNameSpace "CustomerList" To hoRoot
47 // now go through all customer records
48 Send Clear of hoCustomerDD
49 Send Find of hoCustomerDD ge 2
50 While (found)
51 // get name, number and state to strings
52 Move (trim(Customer.Name)) To sName
53 Move Customer.Customer_Number To sNumber
54 Move (trim(Customer.State)) To sState
55 // for each customer create customer node with child elements
56 Get AddElementNS Of hoRoot sNameSpace "Customer" "" To hoEle
57 Send AddElementNS Of hoEle sNameSpace "Name" sName
58 Send AddElementNS Of hoEle sNameSpace "Number" sNumber
59 Send AddElementNS Of hoEle sNameSpace "State" sState
60 Send Destroy Of hoEle
61 Send Find of hoCustomerDD gt 2
62 Loop
63 Function_Return hoXML
64 End_Function
65
66 // Pass XML customer document and parse it. Delete marked
67 // customers. Return a new XML containing a new list of customers
68 { Published = True }
69 { Description = "Passed a customer XML with delete atrributes. Deletes all customers and returns a new list." }
70 Function DelCustomerXMLList XmlHandle CustomerList Returns XmlHandle
71 Handle hoCustomerDD
72 Handle hoRoot hoCust
73 Handle hoRetXml hoRetRoot hoRetCust
74 String sDel sNumber sNs
75 Boolean bDelete
76
77 If not CustomerList function_return 0
78
79 Move Customer_DD to hoCustomerDD
80
81 // namespaceURI of in and out xml doc
82 Move "http://www.dataaccess.com/Test/CustomerList" to sNs
83
84 // this will be our return document
85 Get Create (RefClass(cXmlDomDocument)) to hoRetXml
86 Get CreateDocumentElementNS of hoRetXml sNs "CustomerList" to hoRetRoot
87
88 // go through node list looking for customers to delete
89 Get DocumentElement of CustomerList to hoRoot
90 Get ChildElementNS of hoRoot sNs "Customer" to hoCust
91 While hoCust
92
93 // if attribute "Delete" is "Y" we will delete it
94 Get AttributeValue Of hoCust "Delete" To sDel
95 Move (sDel="Y") to bDelete
96 If (bDelete) Begin
97 // attempt to delete customer
98 Get ChildElementValueNS Of hoCust sNs "Number" To sNumber
99 Send Clear of hoCustomerDD
100 Move sNumber to Customer.Customer_Number
101 Send Find of hoCustomerDD eq 1
102 If (found) Begin
103 // This is commented out because this is a test. We will
104 // remove the customer from the XML list but not from the
105 // data table. This allows the sample to be run over and over.
106
107 //Send Request_delete of hoCustomerDD
108 //If (err) begin
109 // Move False to bDelete
110 //end
111 End
112 End
113 // if not deleted, add the customer node the return document
114 If not bDelete begin
115 Get CloneNode of hoCust true to hoRetCust // clone node and all children
116 Get AppendNode of hoRetRoot hoRetCust to hoRetCust // append to return doc
117 Send destroy of hoRetCust
118 End
119 //
120 Get NextElementNS of hoCust sNs "Customer" to hoCust
121 Loop
122 // note that both the passed xml document and the return document will get
123 // destroyed automatically by the web-service handler
124 Function_Return hoRetXML
125 End_Function
126
127End_Object // oCustXML
128