Durchsuchen und Durchsuchen von Metadaten mithilfe des WCF LOB Adapter SDK
Dieser Abschnitt enthält Informationen zum Verfügbarmachen von Browse- und Suchfunktionen mit einem Adapter durch Implementieren von IMetadataBrowseHandler bzw. IMetadataSearchHandler.
IMetadataBrowseHandler
Beim Hinzufügen eines Adapters zu einem Projekt ermöglicht IMetadataBrowseHandler das Durchsuchen der Vom Adapter unterstützten Kategorien und Vorgänge. Dadurch kann der Adapterconsumer Metadateninformationen zur Entwurfszeit anzeigen und nur die Vorgänge auswählen, die für den Clientprozess erforderlich sind.
Wenn Sie das Add Adapter Service Reference Visual Studio Plug-In oder Consume Adapter Service BizTalk Project Add-In verwenden, um einem Projekt einen Adapter hinzuzufügen, füllt der IMetadataBrowseHandler die Felder Vertragstyp auswählen, Kategorie auswählen und Verfügbare Kategorien und Vorgänge auf.
Im folgenden Beispiel wird veranschaulicht, wie IMetadataBrowseHandler implementiert wird. Es erstellt ein MetadataRetrievalNode-Array, das Informationen zu den Kategorien und Vorgängen enthält, die der Adapter unterstützt.
public class EchoAdapterMetadataBrowseHandler : EchoAdapterHandlerBase, IMetadataBrowseHandler
{
/// <summary>
/// Initializes a new instance of the EchoAdapterMetadataBrowseHandler class
/// </summary>
public EchoAdapterMetadataBrowseHandler(EchoAdapterConnection connection
, MetadataLookup metadataLookup)
: base(connection, metadataLookup)
{
}
#region IMetadataBrowseHandler Members
/// <summary>
/// Retrieves an array of MetadataRetrievalNodes from the target system.
/// The browse operation will return nodes starting from the childStartIndex in the path provided in absoluteName, and the number of nodes returned is limited by maxChildNodes.
/// The method should complete within the specified timespan or throw a timeout exception.
/// If absoluteName is null or an empty string, return nodes starting from the root + childStartIndex.
/// If childStartIndex is zero, then return starting at the node indicated by absoluteName (or the root node if absoluteName is null or empty).
/// </summary>
public MetadataRetrievalNode[] Browse(string nodeId
, int childStartIndex
, int maxChildNodes, TimeSpan timeout)
{
// note we don't support timeout in this sample
if (MetadataRetrievalNode.Root.NodeId.Equals(nodeId))
{
MetadataRetrievalNode node = new MetadataRetrievalNode("EchoMainCategory");
node.DisplayName = "Main Category";
node.IsOperation = false;
node.Description = "This category contains inbound and outbound categories.";
node.Direction = MetadataRetrievalNodeDirections.Inbound | MetadataRetrievalNodeDirections.Outbound;
return new MetadataRetrievalNode[] { node };
}
else if( "EchoMainCategory".CompareTo(nodeId) == 0 )
{
// Inbound operations
MetadataRetrievalNode inOpNode1 = new MetadataRetrievalNode("Echo/OnReceiveEcho");
inOpNode1.DisplayName = "OnReceiveEcho";
inOpNode1.Description = "This operation echoes the location and length of a file dropped in the specified file system.";
inOpNode1.Direction = MetadataRetrievalNodeDirections.Inbound;
inOpNode1.IsOperation = true;
// Outbound operations
MetadataRetrievalNode outOpNode1 = new MetadataRetrievalNode("Echo/EchoStrings");
outOpNode1.DisplayName = "EchoStrings";
outOpNode1.Description = "This operation echoes the incoming string COUNT number of times in a string array.";
outOpNode1.Direction = MetadataRetrievalNodeDirections.Outbound;
outOpNode1.IsOperation = true;
MetadataRetrievalNode outOpNode2 = new MetadataRetrievalNode("Echo/EchoGreetings");
outOpNode2.DisplayName = "EchoGreetings";
outOpNode2.Description = "This operation echoes the incoming Greeting object COUNT number of times in an array of type Greeting.";
outOpNode2.Direction = MetadataRetrievalNodeDirections.Outbound;
outOpNode2.IsOperation = true;
MetadataRetrievalNode outOpNode3 = new MetadataRetrievalNode("Echo/EchoCustomGreetingFromFile");
outOpNode3.DisplayName = "EchoCustomGreetingFromFile";
outOpNode3.Description = "This operation echoes the greeting object by reading its instance from a file. The Greeting object's metadata is obtained from a predefined XSD file.";
outOpNode3.Direction = MetadataRetrievalNodeDirections.Outbound;
outOpNode3.IsOperation = true;
return new MetadataRetrievalNode[] { inOpNode1, outOpNode1, outOpNode2, outOpNode3 };
}
return null;
}
#endregion IMetadataBrowseHandler Members
}
IMetadataSearchHandler
Die Implementierung von IMetadataSearchHandler in einem Adapter bietet die Möglichkeit, zur Entwurfszeit nach verfügbaren Vorgängen zu suchen, indem Sie einen Suchbegriff eingeben, z. B. einen Teil eines Vorgangsnamens. Dies ist sehr nützlich, wenn Ihr Adapter viele Vorgänge enthält, da Sie Suchwerte eingeben können, um die zurückgegebenen Vorgänge einzuschränken.
Wenn Sie das Visual Studio-Plug-In Adapterdienstverweis hinzufügen oder das BizTalk-Projekt-Add-In zum Hinzufügen eines Adapters zu einem Projekt verwenden, löst der IMetadataSearchHandler Suchzeichenfolgen auf, die im Feld Suchen in der Kategorie eingegeben wurden, und gibt eine Liste übereinstimmender Elemente im Feld Verfügbare Kategorien und Vorgänge zurück.
Sie können beim Generieren von WSDL oder Proxy für einen Adapter auch Suchvorgänge mit svcutil.exe durchführen, indem Sie den Suchwert als Abfragezeichenfolge im Format op=value übergeben. Im Folgenden finden Sie ein Beispiel für die Verwendung von svcutil.exe, um nur die Informationen zum Echo/EchoStrings-Vorgang zurückzugeben.
svcutil.exe “echov2://lobhostname/lobapplication?enableAuthentication=False&op=Echo/EchoStrings” /target:metadata
Hinweis
Das WCF LOB Adapter SDK bietet keine standardmäßige Wildcard-Suchfunktion wie Echo* oder %Echo%. Es liegt beim Autor des Adapters, die Funktion zum Abgleich von Wildcards oder Mustern zu implementieren.
Im folgenden Beispiel wird veranschaulicht, wie IMetadataSearchHandler implementiert wird. Es erstellt ein MetadataRetrievalNode-Array, das Informationen zu den Kategorien und Vorgängen enthält, die der Adapter unterstützt.
public class EchoAdapterMetadataSearchHandler : EchoAdapterHandlerBase, IMetadataSearchHandler
{
/// <summary>
/// Initializes a new instance of the EchoAdapterMetadataSearchHandler class
/// </summary>
public EchoAdapterMetadataSearchHandler(EchoAdapterConnection connection
, MetadataLookup metadataLookup)
: base(connection, metadataLookup)
{
}
#region IMetadataSearchHandler Members
/// <summary>
/// Retrieves an array of MetadataRetrievalNodes (see Microsoft.ServiceModel.Channels) from the target system.
/// The search will begin at the path provided in absoluteName, which points to a location in the tree of metadata nodes.
/// The contents of the array are filtered by SearchCriteria and the number of nodes returned is limited by maxChildNodes.
/// The method should complete within the specified timespan or throw a timeout exception. If absoluteName is null or an empty string, return nodes starting from the root.
/// If SearchCriteria is null or an empty string, return all nodes.
/// </summary>
public MetadataRetrievalNode[] Search(string nodeId
, string searchCriteria
, int maxChildNodes, TimeSpan timeout)
{
List<MetadataRetrievalNode> resultList = new List<MetadataRetrievalNode>();
if ("OnReceiveEcho".ToLower().Contains(searchCriteria.ToLower()))
{
MetadataRetrievalNode nodeInbound = new MetadataRetrievalNode("Echo/OnReceiveEcho");
nodeInbound.DisplayName = "OnReceiveEcho";
nodeInbound.Description = "This operation echos the location and length of a file dropped in the specified file system.";
nodeInbound.Direction = MetadataRetrievalNodeDirections.Inbound;
nodeInbound.IsOperation = true;
resultList.Add(nodeInbound);
}
if ("EchoStrings".ToLower().Contains(searchCriteria.ToLower()))
{
MetadataRetrievalNode outOpNode1 = new MetadataRetrievalNode("Echo/EchoStrings");
outOpNode1.DisplayName = "EchoStrings";
outOpNode1.Description = "This operation echoes the incoming string COUNT number of times in a string array.";
outOpNode1.Direction = MetadataRetrievalNodeDirections.Outbound;
outOpNode1.IsOperation = true;
resultList.Add(outOpNode1);
}
if ("EchoGreetings".ToLower().Contains(searchCriteria.ToLower()))
{
MetadataRetrievalNode outOpNode2 = new MetadataRetrievalNode("Echo/EchoGreetings");
outOpNode2.DisplayName = "EchoGreetings";
outOpNode2.Description = "This operation echoes the incoming Greeting object COUNT number of times in an array of type Greeting.";
outOpNode2.Direction = MetadataRetrievalNodeDirections.Outbound;
outOpNode2.IsOperation = true;
resultList.Add(outOpNode2);
}
if ("EchoCustomGreetingFromFile".ToLower().Contains(searchCriteria.ToLower()))
{
MetadataRetrievalNode outOpNode3 = new MetadataRetrievalNode("Echo/EchoCustomGreetingFromFile");
outOpNode3.DisplayName = "EchoCustomGreetingFromFile";
outOpNode3.Description = "This operation echoes the greeting object by reading its instance from a file. The Greeting object's metadata is obtained from a predefined XSD file.";
outOpNode3.Direction = MetadataRetrievalNodeDirections.Outbound;
outOpNode3.IsOperation = true;
resultList.Add(outOpNode3);
}
return resultList.ToArray();
}
#endregion IMetadataSearchHandler Members
}