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).
Answer:
Here is the piece of code just in case anyone is looking for it.
MethodInfo[] methods = typeof(MyClass).GetMethods(BindingFlags.Public | BindingFlags.Instance);
if (methods != null && methods.Length > 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
}
}
}
}
On your client side, since you already have a web reference type for the web service, you can just use reflection to list all the methods in the proxy client class.