How to: Import Metadata into Service Endpoints
This topic explains how to import metadata into a collection of service endpoints and use the service defined in the Getting Started Sample. This topic show how to create a client application that imports metadata from the service and then calls the Add method on the service.
To import metadata into service endpoints
Declare an EndpointAddress object and initialize it with the Uniform Resource Identifier (URI) for the metadata exchange (MEX) address of the service.
Create a WsdlImporter, passing in the metadata previously retrieved, and call ImportAllContracts. This generates a collection of ContractDescription objects. You could also call ImportAllEndpoints or ImportAllBindings, depending upon your needs.
After you have imported the metadata, you will not be able to create a client channel or export the metadata. This is because no type information is available at this point. Type information is required to actually interact with the service or export metadata. To generate the type information, you need to generate code, shown in steps 4 and 5. Alternatively, you could use the MetadataResolver helper class. For more information, see How to: Use MetadataResolver to Obtain Binding Metadata Dynamically.
Generate type information for each contract.
Now you can use this information. The following sample generates C# source code.
System.CodeDom.Compiler.CodeGeneratorOptions options = new System.CodeDom.Compiler.CodeGeneratorOptions(); options.BracingStyle = "C"; System.CodeDom.Compiler.CodeDomProvider codeDomProvider = System.CodeDom.Compiler.CodeDomProvider.CreateProvider("C#"); System.CodeDom.Compiler.IndentedTextWriter textWriter = new System.CodeDom.Compiler.IndentedTextWriter(new System.IO.StreamWriter(outputFile)); codeDomProvider.GenerateCodeFromCompileUnit(generator.TargetCompileUnit, textWriter, options); textWriter.Close();