动态调用WCF服务
2016-02-18 17:17
337 查看
本文转载:http://www.cnblogs.com/wiseant/archive/2010/07/29/1787599.html
原文地址:http://blog.csdn.net/castlooo/archive/2010/05/06/5562619.aspx
客户端调用wcf ,有时需要动态的调用服务端的WCF中的方法,本方法,反射wcf 的接口,动态调用接口中的方法。
主要为,动态绑定,反射动态调用。
本文使用的是nettcpbinding 绑定方式,可修改。
调用方法使用
ExecuteMethod<IService>("net.tcp://192.168.0.1:8001/mex", "Test", new object[] { "参数" })
另外还有一篇贴子可参考:http://hi.baidu.com/meback/blog/item/c140495447258e5d564e0006.html
原文地址:http://blog.csdn.net/castlooo/archive/2010/05/06/5562619.aspx
客户端调用wcf ,有时需要动态的调用服务端的WCF中的方法,本方法,反射wcf 的接口,动态调用接口中的方法。
主要为,动态绑定,反射动态调用。
Code highlighting produced by Actipro CodeHighlighter (freeware)http://www.CodeHighlighter.com/-->public static object ExecuteMethod<T>(string pUrl,string pMethodName, params object[] pParams) { EndpointAddress address = new EndpointAddress(pUrl); Binding bindinginstance = null; NetTcpBinding ws = new NetTcpBinding(); ws.MaxReceivedMessageSize = 20971520; ws.Security.Mode = SecurityMode.None; bindinginstance = ws; using (ChannelFactory<T> channel = new ChannelFactory<T>(bindinginstance,address)) { T instance = channel.CreateChannel(); using (instance as IDisposable) { try { Type type = typeof(T); MethodInfo mi = type.GetMethod(pMethodName); return mi.Invoke(instance, pParams); } catch (TimeoutException) { (instance as ICommunicationObject).Abort(); throw; } catch (CommunicationException) { (instance as ICommunicationObject).Abort(); throw; } catch (Exception vErr) { (instance as ICommunicationObject).Abort(); throw; } } } }
本文使用的是nettcpbinding 绑定方式,可修改。
调用方法使用
ExecuteMethod<IService>("net.tcp://192.168.0.1:8001/mex", "Test", new object[] { "参数" })
另外还有一篇贴子可参考:http://hi.baidu.com/meback/blog/item/c140495447258e5d564e0006.html
相关文章推荐
- Xcode 7安装KSImageNamed失败解决方法
- 添加header后的listview顶部多出divider的处理
- 使用RecyclerView出错: Error inflating class android.support.v7.widget.RecyclerView
- linux--给初学者的建议
- 如何将NSString字符串放入剪贴板
- 解开Android应用程序组件Activity的"singleTask"之谜
- DOM节点类型
- 不能用ajax请求下载文件
- ios block1
- ios经验收藏 使用objection来模块化开发iOS项目
- ios系统和某些移动端background-attachment:fixed不兼容性
- java基础—java的Io操作学习(1)
- 欢迎使用CSDN-markdown编辑器
- java_微信公众号开发笔记
- Linux下Mysql主从同步错误:Slave_SQL_Running: No的解决方案
- Android基础之加载动画
- html5 canvas 画hello ketty
- Netty那点事
- ClassLoader 详解及用途(写的不错)
- centos6.6下安装MySQLdb时出现“error command 'gcc' failed with exit status 1”