locked
WCF EF return as list error RRS feed

  • Question

  • User206446733 posted

    Hi I got the error when return EF as the list. Here are my codes.

    Public Function GetMerchantList() As List(Of Merchant) Implements IMerchant.GetMerchantList
                    Dim ws As New aMerchantService.MerchantServiceClient
    
                    Dim General As New General
                    Dim kWSUrl As String = ""
    
                    Dim endpointAddress = ws.Endpoint.Address
    
                    Dim newEndpointAddress As New EndpointAddressBuilder(endpointAddress)
                    kWSUrl = General.ConvertWsURL("App")
    
                    newEndpointAddress.Uri = New Uri(kWSUrl & "MerchantService.svc")
             ws = New aMerchantService.MerchantServiceClient("BasicHttpBinding_IMerchantService", newEndpointAddress.ToEndpointAddress())
                    Dim Data = ws.GetMerchantList()
    
          Return Data
    End Function

    Class

    Public Function GetMerchantList() As List(Of Merchant)
                    Dim Db As New TTMSEntities
                    Dim Data = (From p In Db.TT_MERCHANT Join r In Db.TT_BRANCH_SETTING On _
                               p.MERCHANT_BRANCH_INTERNAL_NUM Equals r.INTERNAL_NUM _
                               Select New Merchant With {.MerchantID = p.MERCHANT_ID,
                                                         .MerchantName = p.DESCRIPTION,
                                                         .BranchID = r.INTERNAL_NUM,
                                                         .BranchName = r.BRANCH_DESC})
    
                    If Data IsNot Nothing Then
                        Return Data.ToList
                    Else
                        Return Nothing
                    End If
     End Function

    The error

    The error is Error Value of type '1-dimensional array of TTMS.App.WebSites.Data.Merchant' cannot be converted to 'System.Collections.Generic.List(Of TTMS.Web.WebSites.WCF.Merchant)'.

     

    Tuesday, December 10, 2013 3:42 AM

Answers

  • User-417640953 posted

    The error is Error Value of type '1-dimensional array of TTMS.App.WebSites.Data.Merchant' cannot be converted to 'System.Collections.Generic

        Dim Data = ws.GetMerchantList()
    

    Hi noname,

    Thanks for your post.

    Based on the error message, we can see the wcf service return you the Merchant array and it cannot be converted to List<Merchant>.

    Please try below code.

    Dim data As New List(Of Merchant)(ws.GetMerchantList())

    If has any doubt, please feel free to back. Thanks.

    Best Regards!

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, December 12, 2013 8:41 AM
  • User-488622176 posted

    Check the service reference settings that the client :

    Right click on the service reference and select Configure Service Reference.

    In the Collection Type drop-down, select the type System.Collections.Generic.List.

    I believe the reason it defaults to Array is that it is the most compatible when serializing. If you're consuming the service from something that recognizes something more complex, you can configure as I mentioned.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, December 12, 2013 12:32 PM

All replies

  • User-417640953 posted

    The error is Error Value of type '1-dimensional array of TTMS.App.WebSites.Data.Merchant' cannot be converted to 'System.Collections.Generic

        Dim Data = ws.GetMerchantList()
    

    Hi noname,

    Thanks for your post.

    Based on the error message, we can see the wcf service return you the Merchant array and it cannot be converted to List<Merchant>.

    Please try below code.

    Dim data As New List(Of Merchant)(ws.GetMerchantList())

    If has any doubt, please feel free to back. Thanks.

    Best Regards!

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, December 12, 2013 8:41 AM
  • User-488622176 posted

    Check the service reference settings that the client :

    Right click on the service reference and select Configure Service Reference.

    In the Collection Type drop-down, select the type System.Collections.Generic.List.

    I believe the reason it defaults to Array is that it is the most compatible when serializing. If you're consuming the service from something that recognizes something more complex, you can configure as I mentioned.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, December 12, 2013 12:32 PM