views:

852

answers:

3

Hello,

Background: 3-4 weeks experience in Silverlight3/C#/.Net and about 3days worth with the RIA Services concept. (most of my previous questions up to date should explain why)

I am doing a test implementation of Microsoft's RIA services with Silverlight3. This is part of a proof of concept i have to do for a client. So its very basic. I have figured out how build the Silverlight3 project using RIA services etc. So passing and returning strings and int's is no problem at the moment.

But i require to return an ArrayList from my Domain Service Class to my SL3 client. But it seems passing back an ArrayList as is, is not permitted. And my limited knowledge of C# does not aid in doing quick type casting/convertions/etc. This server-side function gets an ArrayList which must be returned to the SL3 client, so i have to do something with it to send it client side.

Question: Does anyone know what should be done to an ArrayList (in c#) to allow a DomainService class function to return it to a calling client/SL3 function?

[NOTE: the majority of my attempts all end in the error: "Service operation named 'myFunctionName' does not conform to the required signature. Both return and parameter types must be an entity type or one of the predefined serializable types."]

Please feel free to request any information you feel would be appropriate. Thank you in advance.

+1  A: 

Not sure that you can return an ArrayList. I guess you should think about returning an IEnumerable instead which will make the service recognize the method as a Read method.

If you have a List or ObservableCollection and wish to bind it to an ItemControl like ComboBox, you can set the ItemsSource on your ItemControl. Use the DisplayPath property on the ItemControl to set the property you wish to display or use a DataTemplate.

<ComboBox>
  <ComboBox.ItemTemplate>
    <DataTemplate>
      <StackPanel Orientation="Horizontal">
        <TextBlock Text={"Binding Path=Property1"}/>
        <TextBlock Text={"Binding Path=Property2"}/>
        <TextBlock Text={"Binding Path=Property3"}/>
      </StackPanel>
    </DataTemplate>
  </ComboBox.ItemTemplate>
</ComboBox>
xamlgeek
Thank you. I managed to return a List<T> item, which seems to have worked. But now i am on a new voyage to find how to get this data to show in a combo box, or as they say to bind the data to the comboBox.
logansama
A: 

Hi Logansama. Did you ever get this to work? If yes, could you post your code for returning an ArrayList from a Domain Service Class? Thanks!

anhonga
A: 

My apologies for not posting the solution i found. Bosses threw more work at me than i could handle. :) Please note my solution may not be the best but since my knowledge in SL and RIA services are so new, i guess it may be excused. Initially i wanted to pass back rather complicated arrays from the code provided by our client, but effort and time restraints allowed me to only get it right to convert and return a List. Hope this helps in some way.

Client Side : Silverlight Code in the MainPage.xaml.cs i have a call to retrieve a list of data from the server side, to display in a dropDown list.

// Function called on load of the SL interface
// 'slayer' is an object of the Domain Service Class server-side
// 'this.gidSessionNumber' is just a number used in the demo to represent a session
public void loadPaymentTypeComboBox()
{
    InvokeOperation<IEnumerable<string>> comboList = sLayer.getPaymentTypeCombo(this.gidSessionNumber);
    comboList.Completed += new EventHandler(popPaymentCombo_complete);
}//function loadAllComboBoxes

// Event handler assigned
public void popPaymentCombo_complete(object sender, EventArgs e)
{
    InvokeOperation<IEnumerable<string>> obj = (InvokeOperation<IEnumerable<string>>)sender;
    string[] list = obj.Value.ToArray();

    // 'paymentTypeDropdown' is the name of the specific comboBox in the xaml file
    paymentTypeDropdown.IsEnabled = true;

    // Assign the returned arrayList as itemSource to the comboBox
    paymentTypeDropdown.ItemsSource = list;
}

In the Domain Service Class i have the associated function:

    [ServiceOperation]
    public List<string> getPaymentTypeCombo(string gidNumber)
    {
        // Build objects from libraries provided by our client
        SDT.Life.LifeCO.clsSystemCreator.CreateSysObjects(gidNumber);
        this.lobjSys = SDT.Life.LifeCO.clsSystemCreator.GetSysObject(gidNumber);

        // Rtrieve the ArrayList from the client's code       
        clsTextList comboList= this.lobjSys.lstPaymentType_PaymentQueue;

        // Get the length of the returned list
        int cnt= (int)comboList.Count();

        // Create the List<string> which will be populated and returned
        List<string> theList= new List<string>();

        // Copy each element from the clsTextList to the List<string>
        for (int i = 0; i < cnt;i++)
        {
            string status= comboList.Item(i).Description;
            theList.Add(status);
        }

        // return the newly populated List<string>
        return theList;
    }//end function getPaymentTypeCombo

logansama

related questions