【发布时间】:2013-02-28 20:15:33
【问题描述】:
此问题与Bug in the dynamic language runtime in combination with IIS 7.5有关
如果我为ChannelFactory 提供正确类型的动态对象,它就会挂起。
dynamic src = "MSFT";
var binding = new BasicHttpBinding();
var endpoint = new EndpointAddress("http://www.restfulwebservices.net/wcf/StockQuoteService.svc");
var channel = new ChannelFactory<IStockQuoteService>(binding, endpoint).CreateChannel();
// this will print just fine
Console.WriteLine(channel.GetStockQuote(src as string));
// this will print just fine
Console.WriteLine(new StockQuoteServiceClient().GetStockQuote(src));
// this will never print and the application will hang with no exceptions
Console.WriteLine(channel.GetStockQuote(src));
- 上面的服务是公开的,不是我的,只要在代码中提供的endpoint添加服务引用就可以自己测试这段代码;
-
StockQuoteServiceClient由“添加服务引用”菜单项创建,可以很好地获取动态对象; - 当我在调试时使用 F5 启动应用程序时,这神奇地不会发生,所有行都打印并且程序正确退出;
- 如果我运行它,然后在执行期间附加调试器,我可以看到它挂在对
channel.GetStockQuote(src)的调用上; - 如果我不管它,程序会吃掉我所有的记忆;
- 仅当我将自己的
ChannelFactory与动态对象一起使用时,它才会挂起,如 cmets 中所述。
为什么我的ChannelFactory 在通过添加服务引用创建的对象运行良好时将动态对象作为参数时挂起?
【问题讨论】:
-
使用反射也可以。 var method = channel.GetType().GetMethod("GetStockQuote"); var value = (StockQuote)method.Invoke(channel, new object[] { src });
标签: .net wcf c#-4.0 wcf-client channelfactory