[Indigo] Generate contract code from the program
Christian shows how to generate the c# service contract code giving wsdl, xml schema, and policies files. If you already have an Indigo service running and you need to generate from your program the contract code, you can use the same Christian's code and simply use System.ServiceModel.MetadataResolver class in order to get all the service metadata information:
MetadataResolver resolver = new MetadataResolver(new EndpointAddress(uri));
// I use HTTP/Get to get from the service its metadata
ServiceEndpointCollection endpoints = resolver.RetrieveEndpointsUsingHttpGet();
// Christian's code....
ServiceContractGenerator generator = new ServiceContractGenerator();
Collection<ContractDescription> contracts = resolver.WsdlImporter.ImportAllContracts();
foreach (ContractDescription contract in contracts)
{
generator.GenerateServiceContractType(contract);
}
using (StreamWriter writer = new StreamWriter(File.Create("Contracts.cs")))
{
new Microsoft.CSharp.CSharpCodeProvider().GenerateCodeFromCompileUnit(
generator.TargetCompileUnit, writer,
new System.CodeDom.Compiler.CodeGeneratorOptions());
}