Defines a named message substructure for a particular persistent class.
<View> element defines the view message substructure for the type persistent class. Multiple views can be defined for each persistent class in the system.
The specified view name has to be unique within the type and its sub-types, although the view can be overriden for each sub-type of type using the <Type> element.
Partial serialization aspects can be defined by listing the properties of type using <Member> element that need to be serialized in the given message substructure. The identity properties of the peristent instance is always serialized, including them into the view is not necessary.
Deep serialization aspects can be defined by including referential and collection properties into the view definition. In these cases the serialization view should be extended by listing all members of the referred class that should be included in the message. To learn more about defining the deep serialization aspects, see <Member> element topic.
Serialization Sample
Animal.cs
public abstract class Animal : Persistent {
public abstract Guid Id { get; set; }
public abstract string Name { get; set; }
public abstract TaxonomyClass Class { get; set; }
public abstract int Age { get; set; }
}
AnimalViews.xml
<WireObjectProtocol xmlns="urn:TechTalk:Genome.Wop.Definition">
<Using namespace="Zoo"/>
<View name="Details" type="Animal">
<Member name="Name" />
<Member name="Class" />
<Member name="Age" />
</View>
<View name="ListItem" type="Animal">
<Member name="Name" />
</View>
</WireObjectProtocol>
ServiceLayer.cs
using Zoo;
using Zoo.Dto;
using Zoo.Dto.Serializers;
[WebService]
public class AnimalSerivces {
[WebMethod]
public AnimalDto GetByName(string name) {
using (Context.Push(ReadOnlyContext.Create())) {
// do some business logic
Animal animal = (Animal)DB.Extent(typeof(Animal))["Name = {0}", name].ToObject();
// serializing the result to a DTO object with view "Details"
return AnimalSerializer.SerializeDetails(animal);
}
}
[WebMethod]
public AnimalDtoCollection GetByClass(TaxonomyClass c) {
using (Context.Push(ReadOnlyContext.Create())) {
// do some business logic
Set animals = DB.Extent(typeof(Animal))["Class = {0}", c];
// serializing the result to a
// DTO object collection with view "ListItem"
return AnimalSerializer.SerializeListItem(animals);
}
}
}
Transferred messages
<GetByNameResponse>
<GetByNameResult>
<AnimalDto>
<Id>1</Id>
<Name>Nemo</Name>
<Class>Fish</Class>
<Age>1</Age>
</AnimalDto>
</GetByNameResult>
</GetByNameResponse>
<GetByClassResponse>
<GetByClassResult>
<AnimalDto>
<Id>1</Id>
<Name>Nemo</Name>
</AnimalDto>
<AnimalDto>
<Id>2</Id>
<Name>Bruce</Name>
</AnimalDto>
<AnimalDto>
<Id>3</Id>
<Name>Oscar</Name>
</AnimalDto>
</GetByClassResult>
</GetByClassResponse>
Deserialization Sample
This example uses the same persistent class and view definitions as the as the serialization sample.
ServiceLayer.cs
using Zoo;
using Zoo.Dto;
using Zoo.Dto.Serializers;
[WebService]
public class AnimalSerivces {
...
[WebMethod]
public void UpdateAge(AnimalDto animalDto) {
using (Context.Push(ShortRunningTrnasactionContext.Create())) {
// connect back the serialized DTO object to the persistent instance
Animal animal = AnimalSerializer.Deserialize(animalDto);
// update the persistent object
animal.Age = animalDto.Age;
// commit the transaction
Context.CommitCurrent();
}
}
[WebMethod]
// this method retreives all fields of the partially serialized DTO instance
public AnimalDto GetDetails(AnimalDto animalDto) {
using (Context.Push(ReadOnlyContext.Create())) {
// connect back the serialized DTO object to the persistent instance
Animal animal = AnimalSerializer.Deserialize(animalDto);
// serializing the result to a DTO object with view "Details"
return AnimalSerializer.SerializeDetails(animal);
}
}
}
Type: TechTalk.Genome.Wop.Definition.Builder.Xml.ViewXmlData
Assembly: TechTalk.Genome.Wop.dll
Version: 4.2.4
Editions: Professional, Community, Evaluation
<Type> Element | <Member> Element