开发者

dynamically read web service methods

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 (obj开发者_如何学JAVAect o in m.GetCustomAttributes(false))
                        {
                            // To identify the method
                            if (o.GetType().Name.Equals("SoapDocumentMethodAttribute")) 
                            {
                                // Get Name using m.Name
                            }
                        }
                    }
                }


Alternatively, if you need to read the methods of a service on-the-fly, this article may be of interest to you, as it illustrates how to create a WCF proxy from WSDL. http://blogs.msdn.com/b/vipulmodi/archive/2008/10/16/dynamic-proxy-and-memory-footprint.aspx

Then you can use reflection (as per Mike's suggestion) to read the list of service methods exposed by the service.


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜