I wrote a sample code as follows, but you need to create the Echo service in the same assembly with your service which you want to get the list of methods:
public System.Collections.Generic.List<string> SendEcho()
{
// Get the current executing assembly and return all exported types included in it:
Type[] exportedTypes = System.Reflection.Assembly.GetExecutingAssembly().GetExportedTypes();
// The list to store the method names
System.Collections.Generic.List<string> methodsList = new System.Collections.Generic.List<string>();
foreach (Type item in exportedTypes)
{
// Check the interfaces implemented in the current class:
foreach (Type implementedInterfaces in item.GetInterfaces())
{
object[] customInterfaceAttributes = implementedInterfaces.GetCustomAttributes(false);
if (customInterfaceAttributes.Length > 0)
{
foreach (object customAttribute in customInterfaceAttributes)
{
// Extract the method names only if the current implemented interface is marked with "ServiceContract"
if (customAttribute.GetType() == typeof(System.ServiceModel.ServiceContractAttribute))
{
System.Reflection.MemberInfo[] mi = implementedInterfaces.GetMembers();
foreach (System.Reflection.MemberInfo member in mi)
{
if (System.Reflection.MemberTypes.Method == member.MemberType)
{
// If you want to have an idea about the method parameters you can get it from here: (count, type etc...)
System.Reflection.ParameterInfo[] pi = ((System.Reflection.MethodInfo)member).GetParameters();
// Check the method attributes and make sure that it is marked as "OperationContract":
object[] methodAttributes = member.GetCustomAttributes(false);
if (methodAttributes.Length > 0 && methodAttributes.Any(p => p.GetType() == typeof(System.ServiceModel.OperationContractAttribute)))
methodsList.Add(member.Name);
}
}
}
}
}
}
}
return methodsList;
}
Hope this helps!