Cross-Model References

Retired Content

The Web Service Software Factory is now maintained by the community and can be found on the Service Factory site.

This content is outdated and is no longer being maintained. It is provided as a courtesy for individuals who are still using these technologies.
This page may contain URLs that were valid when originally published, but now link to sites or pages that no longer exist.

Retired: November 2011

The Service Factory implements the following cross-model references as shown in Figure 1 in the Using the Service Factory to Build Services topic:

  • There are two references from the Service Contract model to the Data Contract model:
    • The Type property of the DataContractMessagePart is a reference to the DataContract model element.
    • The Type property of the DataContractFault is also a reference to the DataContract model element.
  • In the Host Designer model, the ServiceImplementation property of the ServiceReference model element is a reference to the Service model element in the Service Contract model.
  • In The Data Contract model, the Type property of the ReferenceDataType data member element is a reference to a DataContract model element in another model.

The cross-model references are created and resolved by the classes using the Model Bus service. A reference is set by an editor and stored by a type converter, which is associated with a model element property via custom attributes. The next code example is a fragment of the DSL-generated code for the Type property of the DataContractMessagePart model element. (You can find the code in the DomainClasses.cs file in the GeneratedCode folder of the ServiceContractDsl project.)

In the example, the first three attributes have the following functions, respectively:

  • Associates the property editor called ModelElementReferenceEditor with the property.
  • Associates the type converter called ModelBusReferenceTypeConverter with the property.
  • Defines the picker for selecting the referenced model with SupplyFileBasedBrowserConfiguration.
  • Defines the filter applied to the referenced model and the type of the referenced model element by using the picker ApplyElementTypeLimitations. In this case, it is the DataContract in the referenced Data Contract model.
    [System.ComponentModel.Editor(typeof(Microsoft.VisualStudio.Modeling.Integration.Picker.ModelElementReferenceEditor), typeof(System.Drawing.Design.UITypeEditor))]
    [Microsoft.VisualStudio.Modeling.Integration.Picker.SupplyFileBasedBrowserConfiguration("Please choose a DataContract file",  "DataContract files|*.datacontract")]
    public global::Microsoft.VisualStudio.Modeling.Integration.ModelBusReference Type
    return typePropertyStorage;
    TypePropertyHandler.Instance.SetValue(this, value);

The cross-model reference is a ModelBusReference type with a specific structure referred to as a moniker. An example of a moniker is shown below. In this example, Microsoft.Practices.ServiceFactory.DataContracts\DataContractBase\Customer is the reference to the model element Customer inheriting from DataContractBase, and AccountService\CoreDataContract is the path to the model file in the model project.

The following example shows the AccountsService.Customer and the serialized dat in the model file.

type="modelbus://Microsoft.Practices.ServiceFactory.DataContracts.DataContractDslAdapter/ CoreDataContracts/Customer/.\CoreDataContracts.datacontract%2f6ebf62e4-d0d0-4f80-ab80-9e7f0629a032"

References are resolved by the ModelBusReferenceResolver class. An example of how a reference is resolved is shown in the following code fragment. The example method comes from the CrossModelReferenceValidator.cs validator class, which is in the Microsoft.Practices.ServiceFactory.Validation project in the Libraries solution folder.

string referenceElementDisplayName = ValidationEngine.GetUniquePropertyValue(
                ModelBusReferenceResolver.ResolveAndDispose(objectToValidate), "Name");

And ModelBusReferenceResolver.ResolveAndDispose is defined as:

public static ModelElement ResolveAndDispose(ModelBusReference reference)
    using (ModelBusReferenceResolver resolver = new ModelBusReferenceResolver())
        return resolver.Resolve(reference);