Tony Dougherty
New member
- Joined
- Oct 3, 2011
- Messages
- 1
- Location
- Louisville, Kentucky, United States
- Programming Experience
- 5-10
I'm having a heck of a time with two things that "should" be exactly the same.
At the very bottom of my code, you'll see a button.click event with two object arrays that call my webservice asking for a list of POs and a list of Orders. The list of Purchase orders works perfectly, I've used that elsewhere in my form/code. However, the Orders array does not. It contains the correct number of elements but the objects themselves are unknown {Object}. (Conversely, the elements in the PO array can be drilled down into to see the values in each PO instance). This results in the directcast line throwing up an InvalidCastException.
I have also ran it using an internet browser, looking at the asmx page on the server, and it runs perfectly. It displays the elements and all their values.
I'm pretty new to the webservice/xml/serializing stuff so please bear with me and dont use too many big words lol (or use big words but explain them carefully for me).
If you need any more explanation, please let me know. I'm at my wits end with this one.
Tony
At the very bottom of my code, you'll see a button.click event with two object arrays that call my webservice asking for a list of POs and a list of Orders. The list of Purchase orders works perfectly, I've used that elsewhere in my form/code. However, the Orders array does not. It contains the correct number of elements but the objects themselves are unknown {Object}. (Conversely, the elements in the PO array can be drilled down into to see the values in each PO instance). This results in the directcast line throwing up an InvalidCastException.
I have also ran it using an internet browser, looking at the asmx page on the server, and it runs perfectly. It displays the elements and all their values.
I'm pretty new to the webservice/xml/serializing stuff so please bear with me and dont use too many big words lol (or use big words but explain them carefully for me).
If you need any more explanation, please let me know. I'm at my wits end with this one.
Tony
VB.NET:
Imports System.Web.Services
Imports System.Web.Services.Protocols
Imports System.ComponentModel
Imports AccuUtils.Database.OracleConn
' To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the following line.
' <System.Web.Script.Services.ScriptService()> _
<System.Web.Services.WebService(Namespace:="http://har.local/")> _
<System.Web.Services.WebServiceBinding(ConformsTo:=WsiProfiles.BasicProfile1_1)> _
<System.Xml.Serialization.XmlInclude(GetType(PO))> _
<System.Xml.Serialization.XmlInclude(GetType(Order))> _
<ToolboxItem(False)> _
Public Class HardecsWebUtils
Inherits System.Web.Services.WebService
<WebMethod(Description:="Gets a list of the vendors and their open purchase orders (arraylist of type PO)")> _
Public Function GetVendorsAndTheirOpenPOs(ByVal sUserName As String) As ArrayList
Dim strSQL As String = _
"select " & _
"po.id purc_order_id, v.id vendor_id, v.name vendor_name, po.har_receiver_user receiver_user, " & _
"count(pol.line_no) as line_count, sum(pol.user_order_qty) as case_count " & _
"from " & _
"vendor v, purchase_order po, purc_order_line pol " & _
"where " & _
"po.id = pol.purc_order_id and " & _
"po.vendor_id = v.id and " & _
"po.status = 'R' and " & _
"(po.har_receiver_user = '" & sUserName.ToUpper & "' or po.har_receiver_user is null) " & _
"group by " & _
"po.id, v.id, v.name, po.har_receiver_user " & _
"order by " & _
"v.name"
Dim dsVendorPOs As DataSet = sqlConnection.ExecuteQuery("vendorpos", strSQL)
Dim colPOs As New ArrayList
For Each drVendorPO As DataRow In dsVendorPOs.Tables(0).Rows
colPOs.Add(New PO(drVendorPO("vendor_id"), drVendorPO("vendor_name"), drVendorPO("purc_order_id"), _
drVendorPO("line_count"), drVendorPO("case_count"), drVendorPO("receiver_user")))
Next
Return colPOs
End Function
<WebMethod(Description:="Gets a list of the available orders to ship")> _
Public Function GetListOfAvailableOrders(ByVal sUserID As String) As ArrayList
Dim strSQL As String = _
"select " & _
"unique(co.id) order_id, c.name customer_name, c.id customer_id, co.desired_ship_date, co.har_shipping_user " & _
"from " & _
"customer_order co, customer c " & _
"where " & _
"co.customer_id = c.id and " & _
"(co.har_shipping_user = '" & sUserID.ToUpper & "' or co.har_shipping_user is null) and " & _
"co.status = 'R' " & _
"order by " & _
"co.id"
Dim dsOrders As DataSet = sqlConnection.ExecuteQuery("orders", strSQL)
Dim colReturn As New ArrayList
' Add each item to the arraylist
For Each drOrder As DataRow In dsOrders.Tables(0).Rows
colReturn.Add(New Order(drOrder("order_id"), drOrder("customer_id"), drOrder("customer_name"), _
"", 0, 0, "", "", drOrder("desired_ship_date"), _
drOrder("har_shipping_user")))
Next
Return colReturn
End Function
End Class
Public Class Order
Public ID As String
Public CustomerID As String
Public CustomerName As String
Public ShipMethod As String
Public LineItemCount As Integer
Public TotalWeight As Double
Public ShipToAddr As String
Public SoldToAddr As String
Public ShipDate As Date
Public ShippingUser As String
Public Sub New()
End Sub
Public Sub New(ByVal sID As String, ByVal sCustomerID As String, ByVal sCustomerName As String, _
ByVal sShipMethod As String, ByVal iLineItemCount As Integer, ByVal dTotalWeight As Double, _
ByVal sShipToAddr As String, ByVal sSoldToAddr As String, ByVal dShipDate As Date, ByVal sShippingUser As String)
ID = sID
CustomerID = sCustomerID
CustomerName = sCustomerName
ShipMethod = sShipMethod
LineItemCount = iLineItemCount
TotalWeight = dTotalWeight
ShipToAddr = sShipToAddr
SoldToAddr = sSoldToAddr
ShipDate = dShipDate
ShippingUser = sShippingUser
End Sub
End Class
Public Class PO
Public VendorID As String
Public VendorName As String
Public PONum As String
Public LineCount As Integer
Public CaseCount As Integer
Public ReceivingUser As String
Public Sub New()
End Sub
Public Sub New(ByVal sVendorID As String, ByVal sVendorName As String, ByVal sPONum As String, ByVal iLineCount As Integer, ByVal iCaseCount As Integer, ByVal sReceivingUserID As String)
VendorID = sVendorID
VendorName = sVendorName
PONum = sPONum
LineCount = iLineCount
CaseCount = iCaseCount
ReceivingUser = sReceivingUserID
End Sub
End Class
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim Orders() As Object = HarWebUtils.GetListOfAvailableOrders("tdougher")
Dim POs() As Object = HarWebUtils.GetVendorsAndTheirOpenPOs("tdougher")
' Loop through each of the available orders
For intOrderCount As Integer = 0 To Orders.Count - 1
Dim Order As WebUtils.Order = DirectCast(Orders(intOrderCount), WebUtils.Order)
MsgBox(Order.ID & " - " & Order.CustomerName)
Next
End Sub