title: Consume and Invoke SOAP WebServices at Runtime - Dynamic Web Service client from WSDL file
body: <p><strong>Requirement:</strong></p>
  
  <ol>
  <li>Customer to give the SOAP Web-service's WSDL at runtime i.e pick the WSDL file from a file share location.</li>
  <li>Consume the WSDL, and call the Method chosen by the Customer on the UI and handle the response.</li>
  </ol>
  
  <p>I cannot use the MetadataExchangeClient as the WSDL will not be hosted.</p>
  
  <p><strong>Implementation:</strong></p>
  
  <pre><code>var serviceDescription = ServiceDescription.Read(@"C:\Contacts.WSDL");
  var metadataSection = new MetadataSection
  {
  Dialect = MetadataSection.ServiceDescriptionDialect,
  Identifier = serviceDescription.TargetNamespace,
  Metadata = serviceDescription
  };
  
  var metadataSections = new List&lt;MetadataSection&gt; {metadataSection};
  var metadatSet = new MetadataSet(metadataSections);
  var wsdlImporter = new WsdlImporter(metadatSet);
  var services = wsdlImporter.ImportAllEndpoints();
  </code></pre>
  
  <p><strong>Road Blocks:</strong></p>
  
  <ol>
  <li>The above code could not extract the service endpoints at all. So, I had to manually create an service endpoint.</li>
  <li>I could not list out all the methods contained in the above WSDL and its associated Inputs/Outputs in the step (to be used in the variable operationName and operationParameters below)</li>
  </ol>
  
  <blockquote>
  <pre><code>object retVal = instance.GetType().GetMethod(operationName)
                          .Invoke(instance, operationParameters);   // Invoke
  </code></pre>
  </blockquote>
  
  <p>I tried by hard coding the operation name, manually parsed from the WSDL, but then it failed at the parameters. It's expecting a complex type containing the hierarchy as below :</p>
  
  <blockquote>
    <p>ContactInput --> ListOfContacts --> Contact --> FirstName, LastName</p>
  </blockquote>
  
  <p><strong>Next Steps:</strong></p>
  
  <p>If someone could help me fix the roadblocks, then I can proceed with the above approach.</p>
  
  <p>Else, I have to start researching on using the svcutil.exe at runtime</p>
  
  <p>Thanks,
  Dev</p>