Esplorare e cercare metadati usando WCF LOB Adapter SDK
In questa sezione vengono fornite informazioni su come esporre le funzionalità di esplorazione e ricerca con una scheda implementando rispettivamente IMetadataBrowseHandler e IMetadataSearchHandler.
IMetadataBrowseHandler
Quando si aggiunge un adapter a un progetto, IMetadataBrowseHandler consente di esplorare le categorie e le operazioni supportate dall'adapter. Ciò consente al consumer della scheda di visualizzare le informazioni sui metadati in fase di progettazione e di selezionare solo le operazioni necessarie per il processo client.
Quando si usa il componente aggiuntivo Add Adapter Service Reference Visual Studio Plug-in o Consume Adapter Service BizTalk Project Add-in per aggiungere un adapter a un progetto, iMetadataBrowseHandler popolano le caselle Seleziona tipo di contratto, Seleziona categoria e Categorie e operazioni disponibili .
Nell'esempio seguente viene illustrato come implementare IMetadataBrowseHandler. Costruisce una matrice MetadataRetrievalNode contenente informazioni sulle categorie e sulle operazioni supportate dall'adapter.
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
L'implementazione di IMetadataSearchHandler all'interno di un adapter offre la possibilità di cercare operazioni disponibili in fase di progettazione immettendo un termine di ricerca, ad esempio una parte di un nome dell'operazione. Questo è molto utile se la scheda contiene molte operazioni, poiché è possibile immettere i valori di ricerca per limitare le operazioni restituite.
Quando si usa il componente aggiuntivo Add Adapter Service Reference Visual Studio Plug-in o Consume Adapter Service BizTalk Project Add-in per aggiungere un adapter a un progetto, IMetadataSearchHandler risolve le stringhe di ricerca immesse nella casella Cerca nella categoria e restituisce un elenco di elementi corrispondenti nella casella Categorie e operazioni disponibili .
È anche possibile eseguire ricerche con svcutil.exe durante la generazione di WSDL o proxy per una scheda, passando il valore di ricerca come stringa di query nel formato op=value. Di seguito è riportato un esempio di utilizzo di svcutil.exe per restituire solo le informazioni sull'operazione Echo/EchoStrings.
svcutil.exe “echov2://lobhostname/lobapplication?enableAuthentication=False&op=Echo/EchoStrings” /target:metadata
Nota
WCF LOB Adapter SDK non fornisce una funzionalità di ricerca jolly predefinita, ad esempio Echo* o %Echo%. L'autore dell'adattatore prevede l'implementazione di funzionalità di corrispondenza con caratteri jolly o pattern.
Nell'esempio seguente viene illustrato come implementare IMetadataSearchHandler. Costruisce una matrice MetadataRetrievalNode contenente informazioni sulle categorie e le operazioni supportate dall'adapter.
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
}
Vedere anche
Commenti e suggerimenti
https://aka.ms/ContentUserFeedback.
Presto disponibile: Nel corso del 2024 verranno gradualmente disattivati i problemi di GitHub come meccanismo di feedback per il contenuto e ciò verrà sostituito con un nuovo sistema di feedback. Per altre informazioni, vedereInvia e visualizza il feedback per