且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

Visual Studio中的服务引用

更新时间:2023-02-27 11:33:08

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

您可以可以编写自己的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