Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
XML, Serialization, Custom Class - Help Please
Message
From
23/02/2003 03:09:40
Keith Payne
Technical Marketing Solutions
Florida, United States
 
 
To
All
General information
Forum:
ASP.NET
Category:
Web Services
Title:
XML, Serialization, Custom Class - Help Please
Miscellaneous
Thread ID:
00756699
Message ID:
00756699
Views:
44
NOTE: Full code listing at the end of this message (there is lots of code).

I am getting a HTTP 500 error when I Invoke the following Web Method:
    <WebMethod(Description:="Inserts a new lead into the Lead table")> _
        Public Function InsertLead( _
            ByVal LeadTypeID As Integer, _
            ByVal PromotionID As Integer, _
            ByVal SourceID As Integer, _
            ByVal Name As String, _
            ByVal Address As String, _
            ByVal City As String, _
            ByVal State As String, _
            ByVal PostalCode As String, _
            ByVal Country As String, _
            ByVal Phone As String, _
            ByVal Fax As String, _
            ByVal Phone2 As String, _
            ByVal Email As String, _
            ByVal LeadData As String) As DataOperationResult
.
.
.

    End Function
It doesn't go beyond the Function declaration.

DataOperationResult (DOR) is a class I created to pass back general information about the success or failure of the Insert. DOR has some public properties and two collections of custom classes. DOR has a default constructor and so do the class definitions for the collection types. The collections have default accessors too.

I went through all of the iterations to get the service to compile - I didn't know anything about serialization when I started. The problem is that I don't know how to proceed troubleshooting this now that I get the lovely HTTP 500 error.

I suspect the problem has something to do with .NET choking on the serialization at run-time. Any ideas would be helpful.

------------
Here is the full code:

./Class/DataOperationResult.vb
Public Class DORValidationStep
    Public Sub New()
        MyClass.New(0, Nothing, Nothing)
    End Sub
    Public Sub New(ByVal ResultCode As Integer)
        MyClass.New(ResultCode, Nothing, Nothing)
    End Sub
    Public Sub New(ByVal ResultCode As Integer, ByVal Rule As String)
        MyClass.New(ResultCode, Rule, Nothing)
    End Sub
    Public Sub New(ByVal ResultCode As Integer, ByVal Rule As String, ByVal _
UserMessage As String)
        Me.ResultCode = ResultCode
        Me.Rule = Rule
        Me.UserMessage = UserMessage
    End Sub
    Public Property ResultCode() As Integer
        Get
            Return ResultCode
        End Get
        Set(ByVal Value As Integer)
            ResultCode = Value
        End Set
    End Property
    Public Property Rule() As String
        Get
            Return Rule
        End Get
        Set(ByVal Value As String)
            Rule = Value
        End Set
    End Property
    Public Property UserMessage() As String
        Get
            Return UserMessage
        End Get
        Set(ByVal Value As String)
            UserMessage = Value
        End Set
    End Property
    Public Sub Reset()
        ResultCode = 0
        Rule = Nothing
        UserMessage = Nothing
    End Sub
End Class
Public Class DORTable
    Public Sub New()
        MyClass.New(Nothing)
    End Sub
    Public Sub New(ByVal TableName As String)
        Me.TableName = TableName
    End Sub
    Public Property TableName() As String
        Get
            Return TableName
        End Get
        Set(ByVal Value As String)
            TableName = Value
        End Set
    End Property
    Public Property PrimaryKeyName() As String
        Get
            Return PrimaryKeyName
        End Get
        Set(ByVal Value As String)
            PrimaryKeyName = Value
        End Set
    End Property
    Public Property PrimaryKeyValue() As Integer
        Get
            Return PrimaryKeyValue
        End Get
        Set(ByVal Value As Integer)
            PrimaryKeyValue = Value
        End Set
    End Property
    Public Property ResultMessage() As String
        Get
            Return ResultMessage
        End Get
        Set(ByVal Value As String)
            ResultMessage = Value
        End Set
    End Property
    Public Property ErrorMessage() As String
        Get
            Return ErrorMessage
        End Get
        Set(ByVal Value As String)
            ErrorMessage = Value
        End Set
    End Property
    Public Sub Reset()
        TableName = Nothing
        PrimaryKeyName = Nothing
        PrimaryKeyValue = Nothing
        ResultMessage = Nothing
        ErrorMessage = Nothing
    End Sub
End Class
Public Class DORTableCollection
    Inherits System.Collections.CollectionBase
    Default Public ReadOnly Property Item(ByVal index As Integer) As DORTable
        Get
            Return CType(List.Item(index), DORTable)
        End Get
    End Property
    Public Sub Add(ByVal DORTable As DORTable)
        List.Add(DORTable)
    End Sub
    Public Sub Remove(ByVal index As Integer)
        List.RemoveAt(index)
    End Sub
End Class
Public Class DORValidationStepCollection
    Inherits System.Collections.CollectionBase
    Default Public ReadOnly Property Item(ByVal index As Integer) As _
DORValidationStep
        Get
            Return CType(List.Item(index), DORValidationStep)
        End Get
    End Property
    Public Sub Add(ByVal DORValidationStep As DORValidationStep)
        List.Add(DORValidationStep)
    End Sub
    Public Sub Remove(ByVal index As Integer)
        List.RemoveAt(index)
    End Sub
End Class
Public Class DataOperationResult
    Public Sub New()
        MyClass.New(0, Nothing)
    End Sub
    Public Sub New(ByVal ResultFlag As Integer)
        MyClass.New(ResultFlag, Nothing)
    End Sub
    Public Sub New(ByVal ResultFlag As Integer, ByVal ResultMessage As _
String)
        Me.ResultFlag = ResultFlag
        Me.ResultMessage = ResultMessage
    End Sub
    Public Property DORValidationSteps() As DORValidationStepCollection
        Get
            Return DORValidationSteps
        End Get
        Set(ByVal Value As DORValidationStepCollection)
            DORValidationSteps = Value
        End Set
    End Property
    Public Property DORTables() As DORTableCollection
        Get
            Return DORTables
        End Get
        Set(ByVal Value As DORTableCollection)
            DORTables = Value
        End Set
    End Property
    Public Property ResultFlag() As Integer
        Get
            Return ResultFlag
        End Get
        Set(ByVal Value As Integer)
            ResultFlag = Value
        End Set
    End Property
    Public Property ResultMessage() As String
        Get
            Return ResultMessage
        End Get
        Set(ByVal Value As String)
            ResultMessage = Value
        End Set
    End Property
End Class
./InternalService.asmx.vb
Imports System.Web.Services
Imports System.Data.SqlClient

<System.Web.Services.WebService(NameSpace:="http://tms-us.com")> Public _
Class InternalService
    Inherits System.Web.Services.WebService

    <WebMethod(Description:="Inserts a new lead into the Lead table")> _
        Public Function InsertLead( _
            ByVal LeadTypeID As Integer, _
            ByVal PromotionID As Integer, _
            ByVal SourceID As Integer, _
            ByVal Name As String, _
            ByVal Address As String, _
            ByVal City As String, _
            ByVal State As String, _
            ByVal PostalCode As String, _
            ByVal Country As String, _
            ByVal Phone As String, _
            ByVal Fax As String, _
            ByVal Phone2 As String, _
            ByVal Email As String, _
            ByVal LeadData As String) As DataOperationResult

        Dim NewLeadID As Integer
        Dim tempCommand As New SqlCommand(Nothing, sqlconTMS)
        Dim ResultInt As Integer
        Dim Result As New DataOperationResult()
        Dim tempDORTable As New DORTable()
        Dim tempDORValidationStep As New DORValidationStep()

        ' Validate the non-foreign key fields

        ' Name is required
        If Name = "" Then
            Result.ResultFlag = -1
            tempDORValidationStep.Reset()
            tempDORValidationStep.ResultCode = -1
            tempDORValidationStep.Rule = "A Name is required"
            tempDORValidationStep.UserMessage = "A NAME entry is required."
            Result.DORValidationSteps.Add(tempDORValidationStep)
        End If

        ' Address + City & State or Address + PostalCode, phone, phone2 or email required
        If Not (Address <> "" And ((City <> "" And State <> "") Or _
PostalCode <> "") Or Phone <> "" Or Phone2 <> "" Or Email <> "") Then
            Result.ResultFlag = -1
            tempDORValidationStep.Reset()
            tempDORValidationStep.ResultCode = -2
            tempDORValidationStep.Rule = "SHORTENED"
            tempDORValidationStep.UserMessage = "SHORTENED"
            Result.DORValidationSteps.Add(tempDORValidationStep)
        End If

        ' Validate the foreign keys
        sqlconTMS.Open()

        tempCommand.CommandText = "SELECT LeadTypeID FROM LeadType WHERE"+_
" LeadTypeID = " + LeadTypeID.ToString()
        ResultInt = tempCommand.ExecuteScalar()
        If ResultInt <> LeadTypeID Then
            Result.ResultFlag = -1
            tempDORValidationStep.Reset()
            tempDORValidationStep.ResultCode = -3
            tempDORValidationStep.Rule = "SHORTENED"
            tempDORValidationStep.UserMessage = "SHORTENED"
            Result.DORValidationSteps.Add(tempDORValidationStep)
        End If
        tempCommand.CommandText = "SELECT PromotionID FROM Promotion WHERE"+_
" PromotionID = " + PromotionID.ToString()
        ResultInt = tempCommand.ExecuteScalar()
        If ResultInt <> PromotionID Then
            Result.ResultFlag = -1
            tempDORValidationStep.Reset()
            tempDORValidationStep.ResultCode = -4
            tempDORValidationStep.Rule = "SHORTENED"
            tempDORValidationStep.UserMessage = "SHORTENED"
            Result.DORValidationSteps.Add(tempDORValidationStep)
        End If
        tempCommand.CommandText = "SELECT SourceID FROM Source WHERE"+_
" SourceID = " + SourceID.ToString()
        ResultInt = tempCommand.ExecuteScalar()
        If ResultInt <> SourceID Then
            Result.ResultFlag = -1
            tempDORValidationStep.Reset()
            tempDORValidationStep.ResultCode = -5
            tempDORValidationStep.Rule = "SHORTENED"
            tempDORValidationStep.UserMessage = "SHORTENED"
            Result.DORValidationSteps.Add(tempDORValidationStep)
        End If

        ' Check to see if there is already a record with the same Name & Promotion ID
        tempCommand.CommandText = "SELECT LeadID FROM Lead WHERE Name = '" +_
 Name + "' AND Address = '" + Address + "' AND ((City = '" + City +_
 "' AND State = '" + State + "') OR PostalCode = '" + PostalCode + "') AND"+_
" PromotionID = " + PromotionID.ToString()
        ResultInt = tempCommand.ExecuteScalar()
        If ResultInt > 0 Then
            Result.ResultFlag = -1
            tempDORValidationStep.Reset()
            tempDORValidationStep.ResultCode = -6
            tempDORValidationStep.Rule = "SHORTENED"
            tempDORValidationStep.UserMessage = "SHORTENED"
            Result.DORValidationSteps.Add(tempDORValidationStep)
            tempDORTable.Reset()
            tempDORTable.TableName = "Lead"
            tempDORTable.PrimaryKeyName = "LeadID"
            tempDORTable.PrimaryKeyValue = ResultInt
            tempDORTable.ErrorMessage = "SHORTENED"
            Result.DORTables.Add(tempDORTable)
        End If

        If Result.ResultFlag = 0 Then
            With sqldaLead.InsertCommand.Parameters
                .Item("@p_LeadTypeID").Value = LeadTypeID
                .Item("@p_PromotionID").Value = PromotionID
                .Item("@p_SourceID").Value = SourceID
                .Item("@p_Name").Value = Name
                .Item("@p_Address").Value = Address
                .Item("@p_City").Value = City
                .Item("@p_State").Value = State
                .Item("@p_PostalCode").Value = PostalCode
                .Item("@p_Country").Value = Country
                .Item("@p_Phone").Value = Phone
                .Item("@p_Fax").Value = Fax
                .Item("@p_Phone2").Value = Phone2
                .Item("@p_Email").Value = Email
                .Item("@p_LeadData").Value = LeadData
                .Item("@p_OriginalAcquisitionDate").Value = DateTime.UtcNow()
            End With

            sqldaLead.InsertCommand.ExecuteNonQuery()
            NewLeadID = sqldaLead.InsertCommand.Parameters("@p_LeadID").Value
            If NewLeadID > 0 Then
                Result.ResultMessage = "Insert Successful - check DORTable"+_
"(""Lead"").PrimaryKeyValue for the PK of the newly created record."
                tempDORTable.Reset()
                tempDORTable.TableName = "Lead"
                tempDORTable.PrimaryKeyName = "LeadID"
                tempDORTable.PrimaryKeyValue = NewLeadID
                tempDORTable.ResultMessage = "New Lead record added."
                Result.DORTables.Add(tempDORTable)
            Else
                Result.ResultMessage = "Internal Error.  The Lead was not "+_
"added to the database."
                tempDORTable.Reset()
                tempDORTable.TableName = "Lead"
                tempDORTable.PrimaryKeyName = "LeadID"
                tempDORTable.PrimaryKeyValue = NewLeadID
                tempDORTable.ResultMessage = "Internal Error."
                Result.DORTables.Add(tempDORTable)
            End If
        End If
        sqlconTMS.Close()

        Return Result

    End Function

End Class
Next
Reply
Map
View

Click here to load this message in the networking platform