locked
Can't update the entities on the ServiceOperation completed event RRS feed

  • Question

  • I have a method on my DomainService which is marked with the ServiceOperationAttribute:
     

    [ServiceOperation]
    public CustomerEntity SomeServiceOperation(CustomerEntity entity, bool someParameter)
    {
       if (someParameter)
          entity.Name = entity.Name.ToLower();
       else
          entity.Name = entity.Name.ToUpper();
    	return entity;
    }

    I have a button in my Silverlight page to invoke the service operation:
     

    private void _someServiceOperation_Click(object sender, RoutedEventArgs e)
    {
       CustomerEntity customer = (CustomerEntity)(_customerView.CurrentItem);
       CustomerDomainService service = _ctx.DomainContext as CustomerDomainService;
       InvokeOperation op = service.SomeServiceOperation( customer, _upperCaseSwitch );
       op.Completed += new EventHandler( SomeServiceOperationCompleted );
       _upperCaseSwitch = !_upperCaseSwitch;
    }
    
    private void SomeServiceOperationCompleted(object sender, EventArgs e)
    {
       InvokeOperation op = (InvokeOperation)sender;
    
       // How do we now if it's still the same entity without blocking the UI, but that's a side issue.
       CustomerEntity customer = (CustomerEntity)(_customerView.CurrentItem);
       customer.Name = op.Value.Name;
    // I would rather have liked to merge the entity, since I don't know what the service operation did... }

    The DomainDataSource _ctx is bound to a DataGrid and the currently selected item in the grid, the current customer, is bound to a DataForm with a ReadOnlyTemplate and an EditTemplate.

    When I press the button, I get the runtime error in the SomeServiceOperationCompleted:
    System.InvalidOperationException: One or more of the parameters passed to 'SomeServiceOperation' is invalid.
    When I read the RIA overview docs, I see:
    "...
    25.2.1.2 Service Operation Changes
    Service operations are no longer allowed to return entities. Query operations must be used for that purpose.
    ..."

    My problems:

    • I can't update my entity via the service operation anymore. Why? I don't expect my QueryOperation to manipulate my entities, so it's not a logical replacement. The Custom operation isn't working anymore either (see http://silverlight.net/forums/t/117371.aspx)
    • For the sake of the test I changed the signature of my method to return a dummy "int". I still get the same exception.

    So how is the service operation supposed to work in RIA July?

    Wednesday, August 5, 2009 8:40 AM

All replies

  • Hi theo67 ,

    Based on your above code we can see,

    private void _someServiceOperation_Click(object sender, RoutedEventArgs e) { CustomerEntity customer = (CustomerEntity)(_customerView.CurrentItem); CustomerDomainService service = _ctx.DomainContext as CustomerDomainService; InvokeOperation op = service.SomeServiceOperation( customer, _upperCaseSwitch ); op.Completed += new EventHandler( SomeServiceOperationCompleted ); _upperCaseSwitch = !_upperCaseSwitch; }

    We guess the cause of your problem is : when you want to pass the entity of the silverlight CustomerEntity to wcf, but this CustomerEntity  is not the entity of the wcf servive, however, the has the same object name and fields. That's why the exception says the parameter is invalid.

    So we would suggest that you can try to transfer the silverlight's CustomerEntity into WCF's CustomerEntity, and pass it to wcf function.

    Tuesday, August 11, 2009 7:09 AM
  • when you want to pass the entity of the silverlight CustomerEntity to wcf, but this CustomerEntity  is not the entity of the wcf servive,

    That was my first guess as well.

    So we would suggest that you can try to transfer the silverlight's CustomerEntity into WCF's CustomerEntity, and pass it to wcf function.

    But I'm not using WCF here. I simply extend my DomainService with this ServiceOperation-method. RIA generates the operation on the entity class as well. Or are you saying that the ServiceOperation on a RIA DomainService is implemented as a WCF-call????

    Tuesday, August 11, 2009 10:08 AM
  • Problem solved, it was the same broken validation constraints (http://silverlight.net/forums/t/117371.aspx) causing the problem. Now I'm able to pass an entity and return an entity as well in a service operation. Still I have the typical problem that I have to do something with the returned entity on the service callback, since I can't simply merge it via the RIA API.

    Thursday, August 13, 2009 2:29 PM