如何在下拉列表中显示 WCF 中可用的所有方法
如何在下拉列表中显示 WCF 中可用的所有方法。我只需要显示那些向客户端公开的方法。我可以使用以下代码,但它显示的方法比预期多得多。好像显示了全部。
MethodInfo[] methods = typeof(IntlService.ClientDataServiceClient).GetMethods();
//// sort methods by name
Array.Sort(methods,
delegate(MethodInfo methods1, MethodInfo methods2)
{ return methods1.Name.CompareTo(methods2.Name); });
foreach (var method in methods)
{
string methodName = method.Name;
ddlMethods.Items.Add(methodName);
}
如何限制显示仅显示我定义的内容
How can I show all the methods that are available in my WCF in a dropdown. I need to show only those methods that are exposed to the client. I have the following code working, but it displays much more methods than expected. Seems it displays all.
MethodInfo[] methods = typeof(IntlService.ClientDataServiceClient).GetMethods();
//// sort methods by name
Array.Sort(methods,
delegate(MethodInfo methods1, MethodInfo methods2)
{ return methods1.Name.CompareTo(methods2.Name); });
foreach (var method in methods)
{
string methodName = method.Name;
ddlMethods.Items.Add(methodName);
}
How can I restrict the display to show only the ones that I defined
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果您只想获取类定义的方法(在本例中为
IntlService.ClientDataServiceClient
),则可以像这样更改对GetMethods()
的调用:如果您'如果您希望仅获取声明为服务方法的方法,那么您需要检查这些方法的属性:
If you're looking to get only methods defined by your class, in this case,
IntlService.ClientDataServiceClient
, then alter your call toGetMethods()
like this:If you're looking to get only methods that are declared as service methods, then you'll need to examine the attributes on the methods: