简体   繁体   English

使Visual Studio“添加服务引用”功能使用现有的类

[英]Make Visual Studios “Add Service Reference” Feature use an existing Class

When I add a service reference to my Visual Studio 2010 C# project, a new class for one of the types defined in the WSDL will be generated. 当我向Visual Studio 2010 C#项目添加服务引用时,将生成WSDL中定义的类型之一的新类。 A de-facto equivalent definition of that type already exists in our solution in a different assembly. 我们在不同程序集中的解决方案中已经存在事实上相同的该类型定义。

When adding the SoapTypeAttribute to the existing class and replacing the references to the generated class in the generated code, everything runs perfectly and as expected. 将SoapTypeAttribute添加到现有类并在生成的代码中替换对生成的类的引用时,一切都按预期完美运行。

How would I tell Visual Studio to use the existing class in the generated code? 我如何告诉Visual Studio在生成的代码中使用现有的类?

This is not possible... you have to use the Classdefinition of the webservice. 这是不可能的......您必须使用Web服务的Classdefinition。

You could try to define an Interface from your Webservice and derive your Class from that interface as a workaround. 您可以尝试从Webservice定义接口,并从该接口派生您的类作为变通方法。

Does the "Reuse types in existing assemblies" option not do what you want? “重用现有装配中的类型”选项是否不符合您的要求? (under the Advanced menu) (在高级菜单下)

From the docs it appears that is what you are looking for. 文档来看,它正是您所寻找的。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM