I'm new, is this correct???

Discussion in 'ASP .Net Web Services' started by David Lozzi, Sep 19, 2005.

  1. David Lozzi

    David Lozzi Guest

    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!
    --
    David Lozzi
    Web Applications Developer
    dlozzi@(remove-this)delphi-ts.com
    David Lozzi, Sep 19, 2005
    #1
    1. Advertising

  2. David Lozzi

    Brock Allen Guest

    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.

    -Brock
    DevelopMentor
    http://staff.develop.com/ballen

    > 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!
    >
    Brock Allen, Sep 19, 2005
    #2
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. joon
    Replies:
    1
    Views:
    511
    Roedy Green
    Jul 8, 2003
  2. Dan

    correct or not correct?

    Dan, Oct 2, 2003, in forum: HTML
    Replies:
    7
    Views:
    433
  3. J.Ram
    Replies:
    7
    Views:
    641
  4. froil
    Replies:
    12
    Views:
    304
    Gunnar Hjalmarsson
    Mar 2, 2006
  5. Replies:
    2
    Views:
    439
    Thomas 'PointedEars' Lahn
    Mar 11, 2008
Loading...

Share This Page