I'm new, is this correct???

D

David Lozzi

I'm new at web services and XML, however I need to create a web service that
connects to universe (IBM) and returns XML. Here's what i've done so far. Is
it correct? I guess if it returns what I want, its correct... but is there a
better way to do this?

Here's my code:

<WebMethod()> Public Function OrderDetails(ByVal orderno As String) As
XmlDocument
Try
Dim doc As New XmlDocument
Dim str As String = ""
Dim itemcnt As Integer = 0
Dim uvsess As UniSession = UniObjects.OpenSession(UVServer, UVUsername,
UVPassword, UVAccount, "uvcs")
Dim uf As UniFile = uvsess.CreateUniFile("OI")
Dim ur As UniDynArray = uf.Read(orderno)
Dim skus As UniDynArray = ur.Extract(17)
Dim descs As UniDynArray = ur.Extract(18)
Dim qtys As UniDynArray = ur.Extract(22)
Dim stati As UniDynArray = ur.Extract(23)
Dim shipped As UniDynArray = ur.Extract(54)
itemcnt = ur.Dcount(17, 0)
str = "<OrderDetails Number=""" & orderno & """>"
'Invoice Details
str &= "<Invoice>"
str &= "<tracking_id>" & ur.Extract(188).ToString & "</tracking_id>"
str &= "<carrier_code>" & ur.Extract(47).ToString & "</carrier_code>"
str &= "<shipment_date>" & ur.Extract(187).ToString & "</shipment_date>"
str &= "</Invoice>"
'Ship tos
str &= "<Shipto>"
str &= "<merchandise_total>" & uvsess.Oconv(ur.Extract(24).ToString, "MR2")
& "</merchandise_total>" & _
"<shipping_total>" & uvsess.Oconv(ur.Extract(25).ToString, "MR2") &
"</shipping_total>" & _
"<gift_wrap_total>" & uvsess.Oconv(ur.Extract(262).ToString, "MR2") &
"</gift_wrap_total>" & _
"<tax_total>" & uvsess.Oconv(ur.Extract(26).ToString, "MR2") &
"</tax_total>" & _
"<total>" & uvsess.Oconv(ur.Extract(27).ToString, "MR2") & "</total>"
str &= "</Shipto>"
'Items
str &= "<itemcount>" & itemcnt & "</itemcount>"
str &= "<items>"
For i As Integer = 1 To itemcnt
str &= "<item><sku>" & skus.Extract(0, i).ToString & "</sku>" & _
"<description>" & descs.Extract(0, i).ToString & "</description>" & _
"<quantity>" & qtys.Extract(0, i).ToString & "</quantity>" & _
"<status>" & stati.Extract(0, i).ToString & "</status>" & _
"<shippedvia>" & shipped.Extract(0, i).ToString & "</shippedvia>" & _
"</item>"
Next i
str &= "</items>"
str &= "</OrderDetails>"
doc.LoadXml(str)
uf.Close()
UniObjects.CloseSession(uvsess)
Return doc
Catch ex As Exception
Dim doc As New XmlDocument
doc.LoadXml("<item><sku>" & ex.Message & "</sku></item>")
Return doc
End Try
End Function





the XML output

<?xml version="1.0" encoding="utf-8" ?>
- <OrderDetails Number="1.......6">
- <Invoice>
<tracking_id>9..............8</tracking_id>
<carrier_code>UPS</carrier_code>
<shipment_date>06/09/05</shipment_date>
</Invoice>
- <Shipto>
<merchandise_total>54.88</merchandise_total>
<shipping_total>9.95</shipping_total>
<gift_wrap_total />
<tax_total>0.00</tax_total>
<total>64.83</total>
</Shipto>
<itemcount>4</itemcount>
- <items>
- <item>
<sku>7.......X</sku>
<description>T-SHIRT- XXL</description>
<quantity>1</quantity>
<status>06/09/05</status>
<shippedvia>PD</shippedvia>
</item>
- <item>
<sku>6.....A</sku>
<description>SCARF TUBE</description>
<quantity>1</quantity>
<status>06/09/05</status>
<shippedvia>PD</shippedvia>
</item>
- <item>
<sku>8.......A</sku>
<description>GARAGE CAP</description>
<quantity>1</quantity>
<status>06/09/05</status>
<shippedvia>PD</shippedvia>
</item>
- <item>
<sku>5.......A</sku>
<description>WISH YOU</description>
<quantity>1</quantity>
<status>06/09/05</status>
<shippedvia>PD</shippedvia>
</item>
</items>
</OrderDetails>


thanks a million!
 
B

Brock Allen

If you're a client of their webservice you should get their WSDL file and
generate a proxy from it using the SDK tool wsdl.exe. You shouldn't be hand
coding all this XML unless it's a non standards compliant web service.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,997
Messages
2,570,240
Members
46,828
Latest member
LauraCastr

Latest Threads

Top