Service Translator Class

Topics: General Discussion Forum, July and December Releases Forum
Feb 29, 2008 at 5:55 AM
Edited Feb 29, 2008 at 5:56 AM
Hi,
I have a few doubts regarding the creating the Service Translator Class, through the wizard.
here i am able to map the Entitie and DataContract.
Suppose my BE be Customers, and DC be CustomersDataContract.

After Completing the wizard i am able to see like...

namespace CustomerDetails.ServiceImplementation
{
public static class TranslateBetweenCustomerDataContractAndCustomers
{
public static CustomerDetails.DataContracts.CustomerDataContract TranslateCustomersToCustomerDataContract(CustomerDetails.BusinessEntities.Customers from)
{
CustomerDetails.DataContracts.CustomerDataContract to = new CustomerDetails.DataContracts.CustomerDataContract();
to.CustomerID = from.CustomerID;
to.CustomerName = from.CustomerName;
to.CreatedDate = from.CreatedDate;
to.Active = from.Active;
return to;
}


public static CustomerDetails.BusinessEntities.Customers TranslateCustomerDataContractToCustomers(CustomerDetails.DataContracts.CustomerDataContract from)
{
CustomerDetails.BusinessEntities.Customers to = new CustomerDetails.BusinessEntities.Customers();
to.CustomerID = from.CustomerID;
to.CustomerName = from.CustomerName;
to.CreatedDate = from.CreatedDate;
to.Active = from.Active;
return to;
}
}
}

Here i Would like to know what does these 2 methods indicates.
Also if i wanna Insert Something, in that case i wanna translate DC to BE right.
Which method i have to use in this, and while retriving...

Wheather i have to Create another translate class.

Nimesh




Feb 29, 2008 at 4:50 PM
These methods are used for mapping between a DC and a BC (back and forth). So in order to interact with the BL, you will use the translators like the following pseudo code sample used in your adapter:

  MyBE be = TranslateBetween
  TranslateBetweenMyDCAndMyBE inputTranslator = new TranslateBetweenMyDCAndMyBE ();
  TranslateBetweenListOfMyBEAndMyDCResponse outputTranslator = new TranslateBetweenListOfMyBEAndMyDCResponse ();
  MyAction action = new MyAction();
  MyBE input =inputTranslator.TranslateDcToBe(adapterInput);
  List<MyBE> result = action.Execute(input);
  return outputTranslator.TranslateListOfMyBEToMyDCResponse(result);

So basically you call yor action and decouple your BL with transalators so you BL deals only with BEs and/or List of BEs and the translators simple map/convert between types.
You can also create new Translators (manually) and aggregate other translators like with TranslateListOfMyBEToMyDCResponse which use TranslateBetweenMyBCAndMyDC to return the list in the Response type:

public MyDCResponse TranslateListOfMyBEToMyDCResponse(List<MyBE> from)
{
    MyDCResponse to = new MyDCResponse();
    TranslateBetweenMyBEAndMyDC translator = new TranslateBetweenMyBEAndMyDC();
 
    List<MyDC> translatedMyDCs =
        from.ConvertAll<MyDC>(
            delegate(MyBE be)
            {
                return translator.TranslateMyBEToMyDC(be);
            }
        );
 
    to.MyDCs = translatedMyDCs.ToArray();
    return to;
}
Mar 1, 2008 at 1:12 PM
Edited Mar 2, 2008 at 7:39 AM
Hi,
I created service for the GetAllCustomers.
But i am facing diffficulty in the client side,
can you please guide me to do that..
I wanna display everything in a treeview, so how can i code for this to display all the customer names that has retreive from the DB.

I want an assistance in this...
Nimesh
Mar 3, 2008 at 10:29 PM
Please refer to thread: http://www.codeplex.com/servicefactory/Thread/View.aspx?ThreadId=23016.

Thanks,
CF