ResolveModelReference with monikers

Topics: General Discussion Forum, Service Factory Modeling Edition Forum
Apr 28, 2009 at 2:53 PM
Edited Apr 28, 2009 at 2:54 PM
I got recently a question about the usage of monikers and how to resolve a DataContract model element reference from let's say a "DataContractMessagePart" type.
There a couple of ways to do this, depending on the context you need to use it.
If you need to resolve a model reference from within a text template, then you can take as an example the "ResolveTypeAndAddProjectReference" function located in "Service Contract DSL\Dsl\TextTemplates\WCF\CS\" file where you can notice the call to the built in function "ResolveModelReference" that receives the moniker string.
This function return the DataComntract element that lives in the DC model from a moniker property in a Service Contract element like DataContractMessagePart.

private string ResolveTypeAndAddProjectReference(string melMoniker)


      DataContractBase dce = (DataContractBase)ResolveModelReference(melMoniker);

      Microsoft.Practices.Modeling.CodeGeneration.Artifacts.ArtifactLink alink = GetArtifactLink(dce);


      return alink.Namespace + "." + dce.Name;


On the other hand, if you need to call this function from code, like a code gen strategy or some other custom or updated code, you can use some generic function like the one located in "\ServiceFactory.Extenders.HostDesigner.Wcf\Source\Strategies\ServiceModelConfigurationStrategy.cs" file like this:

private TReferencedMEL GetMelReference<TReferencedMEL>(string moniker) where TReferencedMEL : ModelElement


      TReferencedMEL mel =





            return mel;


This will automatically cast to the specified type, in this case it might be a DataContract or some other element in the referenced model.