TypedLists, DataTables & WCF

Posts   
 
    
cjarman66
User
Posts: 22
Joined: 19-Nov-2006
# Posted on: 15-Apr-2008 08:03:06   

Hi

Has anyone managed to return a TypedList over a WCF service. If so could you post the code.

I've managed to do the following: 1. Return a sample/custom datatable over WCF 2. Populate a dataTable from a typedList

But I am not able to return a dataTable populated from a TypedList over WCF.

This would lead me to suspect that there is something specific t the TypedList generated DataTable.

Any ideas?

Thanks

C

Walaa avatar
Walaa
Support Team
Posts: 14993
Joined: 21-Aug-2005
# Posted on: 15-Apr-2008 10:56:52   

Please check the WCF example posted on our website. Check how we return and pass LLBLGen Pro objects (eg. EntityCollection or CustomersEntity) and do the same for your TypedList.

You will need to use ITypedList as your method parameter, and in the service contract specify the following attribute:

[ServiceKnownType(typeof(mySpecificTypedList))]
cjarman66
User
Posts: 22
Joined: 19-Nov-2006
# Posted on: 15-Apr-2008 12:10:23   

Hi

Can you provide the link. I pulled down the example from under WCF example using C# and Adapter earlier.

Searched this for [ServiceKnownType(typeof(mySpecificTypedList))]

No luck.

C

cjarman66
User
Posts: 22
Joined: 19-Nov-2006
# Posted on: 15-Apr-2008 12:11:45   

Sorry misread your post.

I'll give it a go.

jlozina
User
Posts: 17
Joined: 13-Mar-2008
# Posted on: 15-Apr-2008 12:40:31   

Ive tried adding [ServiceKnownType(typeof(mySpecificTypedList))] to the service.

When I try to update the Service Reference it comes back with an error. Metadata contains a reference that cannot be resolved.

cjarman66
User
Posts: 22
Joined: 19-Nov-2006
# Posted on: 15-Apr-2008 21:54:18   

Same here, in that the service client could not be updated.

I tried using both ITypedList and ITypedListLgp2 plus the [ServiceKnownType(typeof(myXXXTypedList))].

cry

Walaa avatar
Walaa
Support Team
Posts: 14993
Joined: 21-Aug-2005
# Posted on: 16-Apr-2008 11:09:51   

You should be using an Interface to define the service contract on both sides (Service and client). Don't use the reference/proxy way.

Please check .NET 3.0+ specific: Windows Communication Foundation (WCF) support in the manual's section "Using the generated code -> Adapter -> Distributed systems -> XML Webservices / WCF support"

jlozina
User
Posts: 17
Joined: 13-Mar-2008
# Posted on: 16-Apr-2008 15:28:57   

I had a look at the documentation and it didnt mention TypedLists at all. Sending IEntity2 & IEntityCollection2 objects via WCF work fine. Its TypedLists/DataTable im having trouble with.

Can you tell me whats wrong with this code

using System; using System.Collections.Generic; using System.Linq; using System.Runtime.Serialization; using System.ServiceModel; using System.Text; using System.Data; using MMS.ORM.TypedListClasses; using SD.LLBLGen.Pro.ORMSupportClasses;

namespace MMS.Service { [ServiceContract] [ServiceKnownType(typeof(LkpClassificationTypedList))]

public interface IMemService
{
    [OperationContract]
    DataTable GetClassificationTypedList();

}

}

using System; using System.Collections.Generic; using System.Linq; using System.Runtime.Serialization; using System.ServiceModel; using System.Text; using System.Data; using MMS.ORM.TypedListClasses; using MMS.ORM.DatabaseSpecific; using MMS.ORM.HelperClasses; using SD.LLBLGen.Pro.ORMSupportClasses;

namespace MMS.Service { public class MemService : IMemService {

    public DataTable GetClassificationTypedList()
    {
        using (DataAccessAdapter adapter = new DataAccessAdapter())
        {

            LkpClassificationTypedList classification = new LkpClassificationTypedList();
            DataTable classificationDataTable = new DataTable();
            adapter.FetchTypedList(classification.GetFieldsInfo(), classificationDataTable, classification.GetRelationInfo());

            return classificationDataTable;
        }

    }

}

}

Thanks

Walaa avatar
Walaa
Support Team
Posts: 14993
Joined: 21-Aug-2005
# Posted on: 16-Apr-2008 18:27:57   

Here is an example (tell me if you want me to attach a working solution):

From service interface file:

[ServiceContract()] [ServiceKnownType(typeof(CustomersEntity))] [ServiceKnownType(typeof(OrdersEntity))] [ServiceKnownType(typeof(EntityCollection))] ** [ServiceKnownType(typeof(ProductsCatalogTypedList))]** public interface INorthwindService { ** [OperationContract] ITypedListLgp2 GetProductsCatalog();** ...

From the Service implementation file:

    [ServiceBehavior(InstanceContextMode = InstanceContextMode.Single, ConcurrencyMode = ConcurrencyMode.Multiple)]
    public class NorthwindService : INorthwindService
    {
        public ITypedListLgp2 GetProductsCatalog()
        {
            using (DataAccessAdapter adapter = new DataAccessAdapter())
            {
                ProductsCatalogTypedList productsCatalog = new ProductsCatalogTypedList();
                adapter.FetchTypedList(productsCatalog);

                return productsCatalog;
            }
            
        }
...

And that's it.

cjarman66
User
Posts: 22
Joined: 19-Nov-2006
# Posted on: 16-Apr-2008 23:26:32   

Hi Walaa

This is pretty much what I have. With the exception of the ServiceBehaviour attribute.

Can you post a working file.

I'm finding that the client service reference can not be built once [ServiceKnownType(typeof(xxxxxxxxTypedList))] is added to the interface.

I presume your using VS2008.

C

[ServiceContract]
    [ServiceKnownType(typeof(MemberEntity))]
    [ServiceKnownType(typeof(EntityCollection))]
    [ServiceKnownType(typeof(MembersTypedList))]
    
    public interface IMembershipService
    {
        [OperationContract]
        IEntity2 GetMemberByMemberId(int memberId);

        [OperationContract]
        ITypedListLgp2 GetMemberList();

     }

and

[ServiceBehavior(InstanceContextMode = InstanceContextMode.Single, ConcurrencyMode = ConcurrencyMode.Multiple)]
    public class MembershipService : IMembershipService
    {
        public IEntity2 GetMemberByMemberId(int memberId)
        {
            MemberEntity memberEntity = new MemberEntity(memberId);
            using (DataAccessAdapter adapter = new DataAccessAdapter())
            {
                adapter.FetchEntity(memberEntity);
            }
            return memberEntity;
        }

        
        public ITypedListLgp2 GetMemberList()
        {
            MembersTypedList members = new MembersTypedList();
            DataAccessAdapter adapter = new DataAccessAdapter();
            IRelationPredicateBucket bucket = null;
            ISortExpression sorter = new SortExpression(MemberFields.Surname | SortOperator.Ascending);
            adapter.FetchTypedList(members, null, 0, sorter, true);
            return members;
        }
    }
cjarman66
User
Posts: 22
Joined: 19-Nov-2006
# Posted on: 16-Apr-2008 23:31:21   

BTW - I'm using LLBLGen 2.5 from Feb 4th

cjarman66
User
Posts: 22
Joined: 19-Nov-2006
# Posted on: 16-Apr-2008 23:37:21   

This is the error text

There was an error downloading 'http://localhost:8731/Design_Time_Addresses/MMS.Service/MembershipService/mex'.
The request failed with the error message:
--
<s:Envelope xmlns:s="http://www.w3.org/2003/05/soap-envelope" xmlns:a="http://www.w3.org/2005/08/addressing"><s:Header><a:Action s:mustUnderstand="1">http://www.w3.org/2005/08/addressing/fault</a:Action></s:Header><s:Body><s:Fault><s:Code><s:Value>s:Sender</s:Value><s:Subcode><s:Value>a:MessageAddressingHeaderRequired</s:Value></s:Subcode></s:Code><s:Reason><s:Text xml:lang="en-AU">No Action header was found with namespace 'http://www.w3.org/2005/08/addressing' for the given message.</s:Text></s:Reason><s:Detail><a:ProblemHeaderQName>a:Action</a:ProblemHeaderQName></s:Detail></s:Fault></s:Body></s:Envelope>
--.
Metadata contains a reference that cannot be resolved: 'http://localhost:8731/Design_Time_Addresses/MMS.Service/MembershipService/mex'.
Metadata contains a reference that cannot be resolved: 'http://localhost:8731/Design_Time_Addresses/MMS.Service/MembershipService/mex'.
If the service is defined in the current solution, try building the solution and adding the service reference again.
jlozina
User
Posts: 17
Joined: 13-Mar-2008
# Posted on: 17-Apr-2008 01:38:46   

I get the same error when trying to update the service reference on the client.

Code I'm using now is

using System; using System.Collections.Generic; using System.Linq; using System.Runtime.Serialization; using System.ServiceModel; using System.Text; using System.Data; using MEM.ORM.TypedListClasses; using SD.LLBLGen.Pro.ORMSupportClasses; using MEM.ORM.HelperClasses;

namespace MEM.Service { [ServiceContract()] [ServiceKnownType(typeof(LkpClassificationTypedList))]

public interface IMemService
{
    [OperationContract]
    ITypedListLgp2 GetClassificationTypedList();

}

}

using System; using System.Collections.Generic; using System.Linq; using System.Runtime.Serialization; using System.ServiceModel; using System.Text; using System.Data; using MEM.ORM.TypedListClasses; using MEM.ORM.DatabaseSpecific; using MEM.ORM.HelperClasses; using SD.LLBLGen.Pro.ORMSupportClasses;

namespace MEM.Service { [ServiceBehavior(InstanceContextMode = InstanceContextMode.Single, ConcurrencyMode = ConcurrencyMode.Multiple)] public class MemService : IMemService {

    public ITypedListLgp2 GetClassificationTypedList()
    {
        using (DataAccessAdapter adapter = new DataAccessAdapter())
        {

            LkpClassificationTypedList classification = new LkpClassificationTypedList();
            adapter.FetchTypedList(classification);

            return classification;
        }

    }

}

}

Is this correct?

Walaa avatar
Walaa
Support Team
Posts: 14993
Joined: 21-Aug-2005
# Posted on: 17-Apr-2008 10:15:30   

I think you are still using the reference/proxy approach rather than using the interface approach.

Anyway I'll attach a complete solution, btw I'm using VS 2005.

(EDIT) Solution is attached, in the client a myTypedList form will show once you run the client, with a grid populated from a typedList fetched from the WCF service.

jlozina
User
Posts: 17
Joined: 13-Mar-2008
# Posted on: 18-Apr-2008 04:09:19   

Thanks alot, using the approach in the example works great, using the service reference in the client approach doesnt.