首页 新闻 会员 周边 捐助

WCF双工模式下,不添加引用,如何动态调用.svc地址?

0
悬赏园豆:20 [已关闭问题] 关闭于 2017-02-09 09:42

传输方式为nettcpbinding 绑定方式,下面这段代码会报错误,错误信息如下:

ChannelFactory 不支持协定 ITaskManage,因为它使用一个或多个操作定义回调协定。请考虑使用 DuplexChannelFactory 而不是 ChannelFactory。

 1 //nettcpbinding 绑定方式
 2          public static object ExecuteMethod<T>(string pUrl, string pMethodName,params object[] pParams)
 3          {
 4                  EndpointAddress address = new EndpointAddress(pUrl);
 5                  Binding bindinginstance = null;
 6                  BasicHttpBinding ws = new BasicHttpBinding();
 7                  ws.MaxReceivedMessageSize = 20971520; 
 8                  bindinginstance = ws;
 9                  using (ChannelFactory<T> channel = new ChannelFactory<T>(bindinginstance, address))
10                  {
11                      T instance = channel.CreateChannel();
12                      using (instance as IDisposable)
13                      {
14                          try
15                          {
16                              Type type = typeof(T);
17                              MethodInfo mi = type.GetMethod(pMethodName);
18                              return mi.Invoke(instance, pParams);
19                          }
20                          catch (TimeoutException)
21                          {
22                              (instance as ICommunicationObject).Abort();
23                              throw;
24                          }
25                          catch (CommunicationException)
26                          {
27                              (instance as ICommunicationObject).Abort();
28                              throw;
29                          }
30                          catch (Exception vErr)
31                          {
32                              (instance as ICommunicationObject).Abort();
33                              throw;
34                          }
35                      }
36                  }
37          }

哪位大神有完整的动态调用.svc程序源码(WCF双工模式下)!!!

雨之秋水的主页 雨之秋水 | 小虾三级 | 园豆:649
提问于:2016-11-10 09:40
< >
分享
所有回答(1)
0

nettcpbinding你new一个BasicHttpBinding来绑定貌似有点问题吧,把binging换成NetTcpBinding试试~

keitsi | 园豆:246 (菜鸟二级) | 2016-11-23 11:01
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册