动态参数的ChannelFactory错误 [英] ChannelFactory bug with dynamic arguments

查看:179
本文介绍了动态参数的ChannelFactory错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这个问题是关系到<一个href="http://stackoverflow.com/questions/10249684/bug-in-the-dynamic-language-runtime-in-combination-with-iis-7-5">Bug在动态语言运行库结合IIS 7.5

的ChannelFactory 挂起,如果我给它提供一个正确类型的动态对象。

ChannelFactory hangs if I provide it with a correctly typed dynamic object.

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));

  • 在服务上面是公开的,不是我的,你可以测试这个$ C C $自己,如果你只需要添加服务引用在code提供的端点;
  • StockQuoteServiceClient 是由添加服务引用菜单项创建,并采取动态对象就好了;
  • 在这个神奇不,当我启动应用程序与F5在调试发生,所有的线条打印,并在程序退出正确;
  • 如果我运行它,然后在执行过程中附加调试我可以看到它挂在调用 channel.GetStockQuote(SRC);
  • 如果我离开它是,该计划吃所有我的记忆中;
  • 当我用挂我自己的的ChannelFactory 动态对象,在注释中描述。
    • The service above is public, is not mine, and you can test this code yourself if you just add the service reference to the endpoint provided in the code;
    • StockQuoteServiceClient was created by the Add Service Reference menu item and takes dynamic objects just fine;
    • This magically doesn't happen when I launch the application with F5 on Debug, all lines print and the program exits correctly;
    • If I run it and then attach the debugger during execution I can see it hung on the call to channel.GetStockQuote(src);
    • If I leave it be, the program eats all my memory;
    • It only hangs when I use my own ChannelFactory with dynamic objects, as described in the comments.
    • 为什么我的的ChannelFactory 挂起时,它需要动态对象作为参数时被创建的添加服务引用运行得很好?

      Why my ChannelFactory hangs when it takes dynamic objects as parameters when the one created by Add Service Reference runs just fine?

      推荐答案

      在使用动态关键字,每code相关的动态变量将在运行时由DLR编译。当你调用使用动态变量的方法,实际的方法签名是未知在编译的时候,也该方法返回类型和一切与之相关的创造一些埃里克利珀所谓的动态传染

      When you use the dynamic keyword, every code related to the dynamic variable will be compiled in run-time by the DLR. When you call a method using a dynamic variable, the actual method signature is unknown in compile time and also the method return type and everything related to it creating something Eric Lippert called "Dynamic Contagion":

      正如我指出的最后一次,当调用的参数是动态   那么赔率是pretty的好,编译器将结果进行分类   的通话动态为好;污点US $ p $垫。事实上,当你   使用几乎任何操作员在动态的前pression,其结果是   动态型,也有少数例外。 (是,例如总是返回   一个布尔值)。你可以治愈的前pression至prevent它那preading   dynamicism通过铸造其对象,或以任何其他非动态   输入您想;铸造动态到对象是一个身份的转换。

      "As I pointed out last time, when an argument of a call is dynamic then odds are pretty good that the compiler will classify the result of the call as dynamic as well; the taint spreads. In fact, when you use almost any operator on a dynamic expression, the result is of dynamic type, with a few exceptions. ("is" for example always returns a bool.) You can "cure" an expression to prevent it spreading dynamicism by casting it to object, or to whatever other non-dynamic type you'd like; casting dynamic to object is an identity conversion."

      WCF内部采用了大量的接口和抽象,并有一个<一个href="https://connect.microsoft.com/VisualStudio/feedback/details/597276/dynamic-runtime-fails-to-find-method-from-a-base-interface-during-runtime"相对=nofollow>有关抽象和接口,其中DLR不能解决正确的类型称为德国航空航天中心的限制。 (也看看这个SO讨论

      WCF internals uses a lot of interfaces and abstractions and there's a known DLR limitation regarding abstractions and interfaces where DLR doesn't resolve the correct type. (Also take a look at this SO discussion)

      我可以使用反射和铸造参数的其他类型(也试图调用使用了错误类型的服务),以正确地调用的ChannelFactory。这个问题必须DLR有关。

      I was able to correctly invoke the ChannelFactory using reflection and casting the parameter to other types (and also trying to invoke the service using the wrong type). The problem must be DLR related.

      我无法调试DLR编译但问题可能与动态传染和界面分辨率错误。随着传染的WCF调用的各个部分可以在运行时编译和类型解析错误可能造成一些endles循环在某些角落情况下,像一个overrided方法实现调用基方法和基类被错误地解析为同一个孩子类。

      I'm unable to debug the DLR compilation but the problem may be related to the "dynamic contagion" and the interface resolution bug. With "contagion" every part of the WCF invocation may be compiled at runtime and the type resolution bug may create some endles loops in some corner cases like an overrided method implementation that invokes the base method and the base class was wrongly resolved to the same child class.

      有些WCF内部执行额外的指令> Debugger.IsAttached )额外的一般在于断言,检查和归属。额外的指令可以提供杀死动态传染,避免了虚假的无限循环的一些信息。

      Some WCF internals executes extra instructions when the debugger is attached (Debugger.IsAttached) that extra generally consists in asserts, checks and attributions. The extra instructions may provide some information that kills the "dynamic contagion" and avoids the bogus endless loop.

      这篇关于动态参数的ChannelFactory错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆