使用动态语言和 DLR 创建 WCF 服务
我很好奇如何使用 IronPython 或 IronRuby 等动态语言来创建基于 WCF 的服务。这些语言没有接口的概念。人们会如何定义服务合同?我们需要依赖静态语言来完成此类任务吗?我尤其是 Python 的忠实粉丝,想知道现在是否可以做到这一点。
I was curious how anyone would go about creating WCF based services using a dynamic language like IronPython or IronRuby. These languages do not have the concept of interfaces. How would someone define service contracts? Would we need to rely on static languages for such kind of tasks? I am a big fan of Python in particular and would like to know if this can be done at this point.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我做了一些实验 - 请参阅我的博客上的经验。
好消息是 WCF 服务可以完全用 IronPython 编写。坏消息是此类 WCF 服务无法在 IIS 中工作,因为您无法直接使用从 C# 或 VB 编译的 IronPython 代码。
I have done some experiments - see my experiences on my blog.
The good news is WCF service can be fully written in IronPython. The bad news is such WCF service does not work in IIS because you cannot use compiled IronPython code from C# or VB directly.
IronPython 在 2.6 中有一个新功能,可以使用 Python 类定义机制创建普通的 .NET 类。新功能是通过重写元类上的 clrtype 来启用的。然后,您可以声明一个带有一堆装饰器的类,并且元类创建一个新的 .NET 类型。作为示例,我们有一组元类,可以在 IronPython CodePlex 站点上使用(或自定义) 2.6.1 版本。
我还没有特别尝试过使用 WCF,但它在其他需要使用静态类型的情况下确实有效。在某些情况下它不起作用 - 特别是当框架需要执行 Type.GetType(typeName) 时。
IronPython has a new feature in 2.6 to create normal .NET classes using the Python class definition machinery. The new feature is enabled by overriding clrtype on a metaclass. You can then declare a class with a bunch of decorators and the metaclass creates a new .NET type. As a sample we have the set of metaclasses which can be used (or customized) over on the IronPython CodePlex site for the 2.6.1 release.
I haven't tried it w/ WCF in particular but it does work in other cases when you need to use a static type. There are some cases where it won't work - particularly if the framework needs to do Type.GetType(typeName).