title: dynamically read web service methods
body: <p>Is there a way to read the web service methods dynamically using a program? I have a windows forms app that should be able to read the list of methods and display them. I have added a service reference to my project but need help to read the list of web methods or operations (WCF).</p>
  
  <hr>
  
  <p><strong>Answer:</strong></p>
  
  <p>Here is the piece of code just in case anyone is looking for it.</p>
  
  <pre><code>    MethodInfo[] methods = typeof(MyClass).GetMethods(BindingFlags.Public | BindingFlags.Instance);
                  if (methods != null &amp;&amp; methods.Length &gt; 0)
                  {
                      foreach (MethodInfo m in methods)
                      {
                          foreach (object o in m.GetCustomAttributes(false))
                          {
                              // To identify the method
                              if (o.GetType().Name.Equals("SoapDocumentMethodAttribute")) 
                              {
                                  // Get Name using m.Name
                              }
                          }
                      }
                  }
  </code></pre>