Hey there, everyone. I'm a long time member, but my responsibilities don't get me into code too often...so, please go easy on me :-D I'm using .Net 4.0, WCF and my goal is to call a webservice - one that is not known at compile time. Now I know that during development, I can right click > Add Service Reference, but that's not what I'm looking for..again the web service won't be known at compile time. So, I've made it as far as to dynamically call a webservice and import all its contracts via the code below (taken from MSDN). And from that I can see all the different web service methods that are available in my webservice (in the string sWSDL at the very top). My question, then: How can I call this web service? I understand the definition, but I don't understand how to invoke it. Any help would be much appreciated.
MetadataExchangeClient mexClient = new MetadataExchangeClient(new Uri(sWSDL), MetadataExchangeClientMode.HttpGet);
mexClient.ResolveMetadataReferences = true;
MetadataSet metaDocs = mexClient.GetMetadata();
WsdlImporter importer = new WsdlImporter(metaDocs);
ServiceContractGenerator generator = new ServiceContractGenerator();
// Add our custom DCAnnotationSurrogate
// to write XSD annotations into the comments.
object dataContractImporter;
XsdDataContractImporter xsdDCImporter;
if (!importer.State.TryGetValue(typeof(XsdDataContractImporter), out dataContractImporter))
{
Console.WriteLine("Couldn't find the XsdDataContractImporter! Adding custom importer.");
xsdDCImporter = new XsdDataContractImporter();
xsdDCImporter.Options = new ImportOptions();
importer.State.Add(typeof(XsdDataContractImporter), xsdDCImporter);
}
else
{
xsdDCImporter = (XsdDataContractImporter)dataContractImporter;
if (xsdDCImporter.Options == null)
{
Console.WriteLine("There were no ImportOptions on the importer.");
xsdDCImporter.Options = new ImportOptions();
}
}
//xsdDCImporter.Options.DataContractSurrogate = new DCAnnotationSurrogate();????
// Uncomment the following code if you are going to do your work programmatically rather than add
// the WsdlDocumentationImporters through a configuration