This is a migrated thread and some comments may be shown as answers.

how to extend InitializeService

1 Answer 55 Views
Data Access Free Edition
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Bruno
Top achievements
Rank 1
Bruno asked on 16 Apr 2015, 11:21 AM

Hi,

I have a question about the generated method InitializeService.

I understand the concept of extending a service with partial classes, but is there a way to extend the InitializeService?

I ask this question because of the following scenario:

suppose you have generated the service:

 

Namespace SofiaCarRentalDataService
<System.ServiceModel.ServiceBehavior(IncludeExceptionDetailInFaults := True)>
Public Class SofiaCarRentalService
        Inherits OpenAccessDataService(Of SofiaCarRentalEntityDiagrams)
Public Shared Sub InitializeService(ByVal config As DataServiceConfiguration)
            config.UseVerboseErrors = True
            config.SetEntitySetAccessRule("*", EntitySetRights.All)
            config.SetServiceOperationAccessRule("GetRentalOrdersForCar", ServiceOperationRights.AllRead)
            config.SetServiceOperationAccessRule("GetProfitForCar", ServiceOperationRights.AllRead)
            config.DataServiceBehavior.MaxProtocolVersion = DataServiceProtocolVersion.V3
End Sub

Protected Overrides Sub HandleException(ByVal args As HandleExceptionArgs)
MyBase.HandleException(args)
End Sub

End Sub
End Class

 

 

the problem with this is that the lines:

            config.SetServiceOperationAccessRule("GetRentalOrdersForCar", ServiceOperationRights.AllRead)
            config.SetServiceOperationAccessRule("GetProfitForCar", ServiceOperationRights.AllRead)

 have to be re-added again and again each time you regenerate the service. Is there a way to extend the InitializeService method in a seperate file?

1 Answer, 1 is accepted

Sort by
0
Viktor Zhivkov
Telerik team
answered on 21 Apr 2015, 08:12 AM
Hello Bruno,

There is no convenient way to customize the InitializeService method body via code.
Fortunately in your scenario it should be fairly easy to just uncheck both Entity types in the step 3 of the Add Service wizard. This will instruct our code generation to skip any uncheck Entity types so no changes will be required in the code.
Another option that you have is to skip overwriting the already generated file. This scenario is useful if you have added some custom code there that you want to keep.

Regards,
Viktor Zhivkov
Telerik
 
OpenAccess ORM is now Telerik Data Access. For more information on the new names, please, check out the Telerik Product Map.
 
Tags
Data Access Free Edition
Asked by
Bruno
Top achievements
Rank 1
Answers by
Viktor Zhivkov
Telerik team
Share this question
or