2013-12-11 3 views
0

안녕하세요 배열을 일반 목록으로 변환 할 때 문제가 있습니다. 아래와 같이 오류가 발생했습니다. 수업에서 이미 ToList로 돌아 왔지만 왜 아직도 나타나지는 않습니다. 이미 서비스 참조 형식을 generic 목록으로 변경하는 것은 기본적으로 Array이지만 System.Collection.GenericList는 System.Collection.Genericlist로 변환 할 수 없습니다. 제발 도와주세요 감사합니다배열을 제네릭 목록으로 변환 할 수 없습니다.

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 
      ' Return ConvertMerchant(Data.ToList) 
     Else 
      Return Nothing 
     End If 
    End Function 

오류

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)'. 
+0

이 문제가있다 : 첫째로, 당신은 반환 할 수있는'T []'배열 방법은'(T의) 목록을 반환 선언 할 때 '. 두 번째 : '상인'클래스 네임 스페이스가 다릅니다. – MarcinJuraszek

+0

'TTMS.App.WebSites.Data.Merchant'는'TTMS.Web.WebSites.WCF.Merchant'와 같지 않습니다. –

+0

'ws.GetMerchantList()'에 대한 코드를 게시하십시오. –

답변

0

서로 다른 두 가지입니다 때문에, 그들은 동일한 경우에도 TTMS.Web.WebSites.WCF.MerchantTTMS.App.WebSites.Data.Merchant를 매핑 할 수 있습니다 논리를 필요 .NET과 관련된만큼 형식이 중요합니다. 이 같은

뭔가 :

Dim MapppedData As New List(Of Data.Merchant) 
Dim Data = ws.GetMerchantList() 

For Each theMerchant As WCF.Merchant In data 
    ' Do logic here to map each of the fields in the 
    ' corresponding Merchant classes 

    ' Add mapped Merchant (Data.Merchant) to the list 

Next 

' Return the mapped list of Data.Merchant objects 
Return MappedData 

업데이트 : 나는 그들이 이런 식으로, 당신의 전화 층에 일치하지 않습니다 있도록 WCF 서비스에 당신의 방법과 클래스 이름을 바꾸는 것이 좋습니다

:

Public Class WsMerchant 

End Class 

Public Function GetMerchants() As List(Of WsMerchant) 

End Function 

이제 WCF 서비스 계층이 충돌하지 않는 개체를 반환하고 있습니다. 이름을 사용하려고하는 레이어와 이름을 바꾸십시오. 따라서 귀하의 전화 기능 (GetMerchantList()가) 지금 이것이다 :

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 MapppedData As New List(Of Merchant) 
    Dim Data = ws.GetMerchantList() 

    For Each theMerchant As WsMerchant In data 
     ' Do logic here to map each of the fields in the WsMerchant class 
     ' to the corresponding Merchant class fields 
     Dim theMappedMerchant As New Merchant 
     theMappedMerchant.Name = theMerchant.Name 


     ' Add mapped Merchant (Merchant) to the list 
     MappedData.Add(theMappedMerchant) 
    Next 

    ' Return the mapped list of Merchant objects 
    Return MappedData 
End Function 
+0

나는 이미 위와 같이 시도하지만 작동하지 않습니다. 미안 해요 WCF 개발에 새로운. 자세한 내용을 알려 주시면 기쁘게 생각합니다. Thx – user3051461

+0

@ user3051461 - 대답이 업데이트되었습니다. –

+0

Data.Merchant를 WCF.Merchant로 변환하는 중 오류가 발생했습니다. – user3051461

관련 문제