2013-12-09 90 views
0

嗨我得到了錯誤,當返回EF作爲列表。這是我的代碼。WCF EF返回列表

WCF

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 

商家類

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 

該錯誤類型的錯誤值 ' TTMS.App.WebSites.Data.Merchant的1維陣列' 不能被轉換到 'System.Collections.Generic.List(Of TTMS.Web.WebSites.WCF.Merchant)'。

請大家幫忙。謝謝

回答

2

它看起來像你使用服務的參考。默認情況下,WCF會將通用列表序列化爲數組。要覆蓋此行爲,請在添加服務引用時單擊左下角的「高級」按鈕。這將顯示服務參考設置。選擇System.Generics.List的集合類型(默認爲System.Array):

enter image description here