How to: Generate a WSDL from a WCF LOB Adapter
Add Adapter Service Reference Visual Studio Plug-In generates a Common Language Runtime (CLR) objects in C#, VB, J#, etc. and Consume Adapter Service BizTalk Project Add-In generates XML Schemas. You can use one of the following methods to generate a Web Servce Description Language (WSDL) file for selected operations.
1) Using Microsoft.ServiceModel.Channels.Tools.MetadataSearchBrowse.MetadataUserControl GetWsdl() method
2) Using Microsoft.ServiceModel.Channels.MetadataRetrievalClient GetMetadata() method
namespace Resolve_MetadataRetrievalClient
{
class Program
{
static void Main(string[] args)
{
// create the binding
SampleAdapterBinding binding = new SampleAdapterBinding();
// create the endpoint address
EndpointAddress address = new EndpointAddress("sample://localhost/SQLOLEDB/AdventureWorks?Protocol=TCPIP&Driver=Test");
// create metadata retrieval client
MetadataRetrievalClient metadataProxy = new MetadataRetrievalClient(binding, address);
// Show the nodes on the console
MetadataRetrievalNode op1 = new MetadataRetrievalNode("/Echo/EchoIntArray");
MetadataRetrievalNode op2 = new MetadataRetrievalNode("/Echo/EchoComplexObject");
op1.IsOperation = true;
op2.IsOperation = true;
List<MetadataRetrievalNode> nodes = new List<MetadataRetrievalNode>();
nodes.Add(op1);
nodes.Add(op2);
// Get the WSDL
ServiceDescription wsdl = metadataProxy.GetMetadata(nodes.ToArray());
// Write the WSDL to a file
string wsdlFileName = @"c:\temp\EchoContract.wsdl";
Console.WriteLine("Writing " + wsdlFileName + "from binding " + binding.Name + "...");
wsdl.Write(wsdlFileName);
// close the proxy
metadataProxy.Close();
}
}
}
3) Using System.ServiceModel.Description.MetadataExchangeClient GetMetadata() method
using System;
using System.ServiceModel;
using WSDL = System.Web.Services.Description;
using System.ServiceModel.Description;
namespace CodeSnippet_Resolve
{
class Program
{
static void Main(string[] args)
{
// Set operations for which WSDL needs to be created
string op1 = "/Echo/EchoIntArray";
string op2 = "/Echo/EchoComplexObject";
// Retrieve WSDL using MEX
EndpointAddress mexAddress = new EndpointAddress("sample://localhost/SQLOLEDB/AdventureWorks?Protocol=TCPIP&Driver=Test" + "&op=" + op1 + "&op=" + op2);
// Create a metadata exchange client to retrieve metadata as per WS-MEX standard
MetadataExchangeClient mexClient = new MetadataExchangeClient(mexAddress);
// Obtain the metadata
MetadataSet metadataSet = mexClient.GetMetadata(mexAddress);
// Retrieve the first service description found
WSDL.ServiceDescription wsdl = (WSDL.ServiceDescription) metadataSet.MetadataSections[0].Metadata;
// Write the WSDL to a file
string wsdlFileName = @"c:\temp\EchoContract.wsdl";
Console.WriteLine("Writing " + wsdlFileName + "...");
wsdl.Write(wsdlFileName);
}
}
}
4) Using Svcutil.Exe /t:metadata
C:\>svcutil /t:metadata "sample://localhost/SQLOLEDB/AdventureWorks?Protocol=TCPIP&Driver=Test&op=/Echo/EchoIntArray&op=/Echo/EchoComplexObject "
Microsoft (R) Service Model Metadata Tool
[Microsoft (R) Windows (R) Communication Foundation, Version 3.0.4506.30]
Copyright (c) Microsoft Corporation. All rights reserved.
Attempting to download metadata from 'sample://localhost/SQLOLEDB/AdventureWorks?Protocol=TCPIP&Driver=Test&op=/Echo/EchoIntArray&op=/Echo/EchoComplexObject' using WS-Metadata Exchange. This URL does not support DISCO.
Saving downloaded metadata files...
C:\my.samples.codesnippets.wsdl
C:\>
For #3 and #4 to work, ensure you have the metadata exchange client endpoint defined in the WCF configuration.
<system.serviceModel>
<client>
<endpoint binding="sampleAdapterBinding" contract="IMetadataExchange" name="sample" />
</client>
</system.serviceModel>
Comments
Anonymous
July 08, 2007
See following posts for more information on this topic. How to: Browse/Search metadata from WCF LOB AdapterAnonymous
February 21, 2012
Firstly, thanks for the example...as it has worked perfectly fine for me. However I do need to know if there's a way to provide the username or password (credentials) in the URI itself?