This thread looks to be a little on the old side and therefore may no longer be relevant. Please see if there is a newer thread on the subject and ensure you're using the most recent build of any software if your question regards a particular product.
This thread has been locked and is no longer accepting new posts, if you have a question regarding this topic please email us at support@mindscape.co.nz
|
Hi, following your new approach in LS 4, I enbraced your enhanced support of DataContract attributes in designer generated code. As I am not aware of any updated samples or documentation covering the new features, I am probably mishandling the whole concept, but the especially the mapping of associations is really confusing me. Prior to LS 4 Jeremy pointed out in this entry http://www.mindscapehq.com/forums/Thread.aspx?PostID=11823 that the mapping had to be done manually. Our DTO templates dont generate any properties for associations, primarily because this would lead to a default position of large graphs being sent over the network when passing around entities (due to the serializer wanting to eagerly load the association data) so this could quickly lead to degraded performance so we wanted this to be a clearly considered addition on your part. Therefore I was very pleased when LS 4 introduced a decoration of properties for associations with the DataMember attribute. Unfortunately Microsofts WCF Test Client was unable to obtain appropriate metadata due to an exception in the DataContractSerializerOperationBehavior class (Mindscape.LightSpeed.EntityCollection seems to be an "invalid collection type"; the original exception message is unfortunately in German). After I removed the DataMember attribute for the associated collection directly in the generated code, I was still not able to invoke a service call successfully as the Microsofts WCF Test Client could not handle the decorated backreference property due to an ObjectDisposedException (apparently my UnitOfWork is released prematurely) Can you give me some directions (a complete example would be extremely helpful) on this issue?
|
|
|
Have a look at the small sample Ive posted in this thread for a starter: http://www.mindscapehq.com/forums/Thread.aspx?ThreadID=3900 If you are exposing a custom service, you may want to have a look at using the base class which we have provided (EntityServiceBase) which provides the plumbing for instantiating and disposing your UnitOfWork within a WCF operation context. Ill look to update the sample with a quick example of this over the next day and post an updated copy of it when this is done. For the association collections you need to make sure they have a property setter to support serialization, Ive updated the default templates in the current nightly to do this for you.
Jeremy |
|
|
Hi Jeremy, thank you very much for your response. Unfortunately I am not making any progress. A) The nightly build 11/01/20 did not solve my problem. As soon as a association collection is included and decorated with the DataMemberAttribute the service is not accessible due to the mentioned exception expressing, that Mindscape.LightSpeed.EntityCollection appears to be an "invalid collection type". The setter exists definitely, as I can see in the generated code. I begin to suspect, that I misunderstand this issue completely, can you therefore please provide a foolproof receipe? B) Looking thoroughly at your example, I was trying to adapt it, by using a IIS 7 instance to host the service. The problem seems to be, that in order to let IIS host the service, I need to initialize DistributedUnitOfWorkService with a parameter-less constructor. Using a DistributedUnitOfWorkService.svc and web.config file containing <%@ ServiceHost Language="C#" Debug="true" Service="Mindscape.LightSpeed.ServiceModel.DistributedUnitOfWorkService" %> and [...] accordingly, when trying to build a service reference the following exception is thrown System.InvalidOperationException was unhandled How can I achieve the correct hosting? Have a nice weekend.
|
|
|
For A: Ensure you are using the NetDataContractSerializer for any EntityCollections you are exposing - there is an attribute available in the Mindscape.LightSpeed.ServiceModel assembly to help with this and you can use it to decorate the applicable service operations. e.g. from the example, INewsContract.cs: [ServiceContract]
For B: The DistributedUnitOfWorkService has been designed as a singleton, so it is intended that you would create the host instance directly (e.g. create it in your Global.asax start up code if you are running within a web application). Make sure you have a specific address for the endpoint specified. e.g. var host = new ServiceHost(new DistributedUnitOfWorkService(new LightSpeedContext<ModelUnitOfWork>("default"))); host.Open(); ...
I will have a look at extending this to support being multi-entrant with a default constructor so you can host it via a .svc as you are thinking - the only limitation will be around the context it uses. Currently the constructor is used to specify the appropriate LightSpeed context for creating the underlying UnitOfWork instance for the service but I think we should be able to work around this with a little bit of extra configuration.
Jeremy |
|