Visual Studio中的服务引用 [英] Service References in Visual Studio

查看:94
本文介绍了Visual Studio中的服务引用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,

是否可以自定义Visual Studio 2010如何生成服务参考?像T4模板一样?

作为一个更具体的示例,我创建了一个自定义数据服务,它将多个WCF数据服务聚合到一个数据服务中.现在,我可以创建对此服务的服务引用,没问题,但是,我想向创建的代理类中添加一些功能-以允许调用服务功能.

Hi Guys,

It it possible to customise how visual studio 2010 generates a service reference? With something like a T4 template?

As a more specific example, I have created a Custom Data Service that aggregates a number of WCF Data Services into a single Data Service. Now I can create a service reference to this service, no problems, however, I want to add a few functions to the created proxy class - to allow Service Functions to be called. Is this possible?

推荐答案

否,这不可能.向导后面发生了很多事情,您无法真正定制生成的输出,超出了向导提供的内容(在高级"下).

您可以可以编写自己的T4来生成必要的类/接口,尽管它不会像内置的添加Web参考"向导那样进行自动发现,刷新WSDL和模式等.做.因此,每当Web服务的合同中发生某些更改(方法名称,参数,类型等等)时,它就可能会中断.我认为这真的不值得.

取而代之的是,考虑为它输出的MyWebServiceClient类简单地编写(或生成一个)包装类.
No, it isn''t possible. There''s a lot going on behind the wizard and you can''t really customize the generated output beyond what the wizard provides (under Advanced).

You could write your own T4 to generate the necessary classes/interfaces, although it won''t do automatic discovery, refreshing of the WSDL and schemas, etc., like the built-in Add Web Reference wizard does. So it would probably break every time something changed in the web service''s contracts (method names, parameters, types, that sort of thing). Not really worth it, in my opinion.

Instead, consider simply writing (or generating?) a wrapper class for the MyWebServiceClient class that it outputs.


我认为向导会生成一个局部的服务引用魔术类.因此,您可以在未经修改的代码中创建另一个同名的局部类,以向魔术添加功能.我们的一个应用程序对WCF客户端魔术类做了类似的操作.
I think the wizard produces a service reference magic-class which is partial. So you can create another partial class of the same name in un-magicked code to add functionality to the magic. One of our applications did something similar with a WCF client magic-class.


您可以根据需要向生成的代理类添加尽可能多的函数/方法,只是要知道每次重新生成时使用向导创建代理,您将不得不重新创建这些方法.请注意,如果您不想使用向导,也可以手动生成代理类.在CP上查看此文章,为您提供一些选择
WCF代理生成选项 [
You can add as many functions/methods to the generated proxy class as you like, just be aware that everytime you regenerate the proxy using the wizard, you will have to recreate these methods. Note that it is also possible to generate the proxy class by hand if you do not want to use the wizard. Take a look at this article here on CP to give you a few options
WCF Proxy Generation Options[^]. Good luck!

Hope this helps


这篇关于Visual Studio中的服务引用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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