添加方法以生成 WCF 客户端代理代码
我想在 WCF 客户端代理代码(即从 ClientBase
派生的生成的类)中为每个服务操作添加一个附加方法。我编写了一个具有 IOperationContractGenerationExtension
实现的 Visual Studio 扩展,但该接口似乎仅公开了修改服务接口的功能,而不是 ClientBase
派生类。
有没有办法在代理客户端类中生成新方法?
I'd like to add one additional method for each service operation in my WCF client proxy code (i.e. the generated class that derives from ClientBase
). I have written a Visual Studio extension that has an IOperationContractGenerationExtension
implementation, but this interface only seems to expose the ability to modify the service interface, not the ClientBase
-derived class.
Is there any way to generate new methods in the proxy client class?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
据我所知,这些类始终是部分类:
因此您可以使用自己的第二个文件轻松扩展它们,该文件将方法添加到同一部分类:
YourOwnFile.cs >
As far as I know, those classes are always partial classes:
so you can easily extend them with your own, second file that adds method to the same partial class:
YourOwnFile.cs
我通过在导入过程中为 ClientBase 派生类生成一个包装类来解决这个问题。实际上,我首先尝试生成一个与客户端类同名的附加分部类,但这导致其余的代码生成停止正常工作。
所以我最终生成的代码看起来像这样:(
由内置 WCF 代理生成器生成):(
由我的自定义
IOperationContractGenerationExtension
生成):注意:我使用的是 Silverlight,所以这就是为什么一切都是异步的。
I got around this by generating a wrapper class for the ClientBase-derived class during the import process. I actually first tried generating an additional partial class with the same name as the client class, but that caused the rest of the code generation to stop working properly.
So my final generated code looks something like:
(generated by the built-in WCF proxy generator):
(generated by my custom
IOperationContractGenerationExtension
):Note: I'm using Silverlight, so that's why everything is async.