日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

动态调用WCF服务[转]

發布時間:2023/12/13 编程问答 22 豆豆
生活随笔 收集整理的這篇文章主要介紹了 动态调用WCF服务[转] 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

原文地址:http://blog.csdn.net/castlooo/archive/2010/05/06/5562619.aspx

?

客戶端調用wcf ,有時需要動態的調用服務端的WCF中的方法,本方法,反射wcf 的接口,動態調用接口中的方法。

主要為,動態綁定,反射動態調用。

?

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

轉載于:https://www.cnblogs.com/wiseant/archive/2010/07/29/1787599.html

創作挑戰賽新人創作獎勵來咯,堅持創作打卡瓜分現金大獎

總結

以上是生活随笔為你收集整理的动态调用WCF服务[转]的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。