Metadata Search Browse API
WCF LOB Adapter SDK provides API for browsing, searching and resolving metadata besides the Add Adapter Service Reference Visual Studio Plug-In/Consume Adapter Service BizTalk Project Add-In tools. This client is called Microsoft.ServiceModel.Channels.MetadataRetrievalClient and is available in Microsoft.ServiceModel.Channels.dll assembly.
namespace Microsoft.ServiceModel.Channels
{
public class MetadataRetrievalClient : ClientBase<IMetadataRetrievalContract>, IMetadataRetrievalContract
{
public MetadataRetrievalClient();
public MetadataRetrievalClient(string endpointConfigurationName);
public MetadataRetrievalClient(string endpointConfigurationName, EndpointAddress remoteAddress);
public MetadataRetrievalClient(string endpointConfigurationName, string remoteAddress);
public MetadataRetrievalClient(System.ServiceModel.Channels.Binding binding, EndpointAddress remoteAddress);
public MetadataRetrievalNode[] Browse(string nodeId, int childStartIndex, int maxChildNodes);
public MetadataRetrievalNode[] Search(string nodeId, string searchCriteria, int maxChildNodes);
public ServiceDescription GetMetadata(MetadataRetrievalNode[] nodes);
}
}
The MetadataRetrievalClient communicates with the adapter using WCF.
Here is a sample of using MetadataRetrievalClient.Browse. The client endpoint configuration is specified in code (and not app.config).
namespace CodeSnippet_Browse
{
class Program
{
static void Main(string[] args)
{
// create the binding
SampleAdapterBinding binding = new SampleAdapterBinding();
// create the endpoint address
EndpointAddress address = new EndpointAddress("sample://localhost/DB2OLEDB/AdventureWorks?Protocol=TCPIP&Driver=Test");
// create metadata retrieval client
MetadataRetrievalClient metadataProxy = new MetadataRetrievalClient(binding, address);
// Show the nodes on the console
Console.WriteLine("Browsing " + binding.Name + "...\n");
// Browse the nodes
MetadataRetrievalNode[] nodes = OutputMetadataTree(metadataProxy, null, 0);
metadataProxy.Close();
}
// This method browses the adapter for category and operation nodes
// and displays them on the conosole.
private static MetadataRetrievalNode[] OutputMetadataTree(IMetadataRetrievalContract proxy, MetadataRetrievalNode node, int depth)
{
for (int i = 0; i < depth; i++)
{
if (i < depth - 1)
{
Console.Write(" ");
}
else
{
Console.Write("└──");
}
}
Console.WriteLine(node == null ? "Root" : node.NodeId + " (" + node.Direction + ")" );
MetadataRetrievalNode[] rootNodes = proxy.Browse(node == null ? MetadataRetrievalNode.Root.NodeId : node.NodeId, 1, 100);
foreach (MetadataRetrievalNode childNode in rootNodes)
{
OutputMetadataTree(proxy, childNode, depth + 1);
}
return rootNodes;
}
}
}
Here is a sample of using MetadataRetrievalClient.Search. The client endpoint configuration is specified in app.config.
namespace CodeSnippet_Search
{
class Program
{
static void Main(string[] args)
{
// Create metadata retrieval client using app.config
MetadataRetrievalClient metadataProxy = new MetadataRetrievalClient("SampleAdapterBinding_IMetadataRetrievalContract");
// Start searching for the nodes
Console.WriteLine("Searching " + metadataProxy.Endpoint.Binding.Name + "...\n");
// Search the nodes
MetadataRetrievalNode[] nodes = metadataProxy.Search("/StoredProcedures", "TDDS", 100);
// Use the node
foreach (MetadataRetrievalNode node in nodes)
{
Console.WriteLine(node.DisplayName + " (" + node.Direction + ")");
}
Console.WriteLine();
// close the client
metadataProxy.Close();
}
}
}
Application configuration for above code is as follows:
<?xml version="1.0" encoding="utf-8"?>
<configuration xmlns="https://schemas.microsoft.com/.NetConfiguration/v2.0">
<system.serviceModel>
<bindings>
<sampleAdapterBinding>
<binding name="SampleAdapterBinding" closeTimeout="00:01:00"
openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:01:00"
overrideWsdlBuilder="false" usePredefinedSchemas="true" count="4"
enablePerfCounters="false" enableConnectionPooling="true" />
</sampleAdapterBinding>
</bindings>
<client>
<endpoint
address="sample://localhost/DB2OLEDB/AdventureWorks?Protocol=TCPIP&Driver=Test"
binding="sampleAdapterBinding"
bindingConfiguration="SampleAdapterBinding"
contract="Microsoft.ServiceModel.Channels.IMetadataRetrievalContract"
name="SampleAdapterBinding_IMetadataRetrievalContract" />
</client>
</system.serviceModel>
</configuration>
Comments
Anonymous
July 08, 2007
Adapter consumer can browse/search metadata from WCF LOB Adapter using following ways: Using Add AdapterAnonymous
July 08, 2007
Add Adapter Service Reference Visual Studio Plug-In generates a CLR objects and Consume Adapter Service