在 .NET 项目中管理 2 个具有共享类依赖项的 Web 引用 [英] Managing 2 web references with shared class dependency in a .NET project

查看:19
本文介绍了在 .NET 项目中管理 2 个具有共享类依赖项的 Web 引用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个包含 2 个 asmx 文件的 Web 服务项目.我们称它们为 internal.asmx &external.asmx 实际上,它们有不同的客户端:

客户端将在外部调用 externalWS.PersistOrder(Order order),而在内部,我们处理订单 internalWS ProcessOrder(Order order).因此,Order 类是这些网络服务之间的共享依赖项.

我正在编写一个测试应用程序,它在这两个网络服务上调用不同的网络方法.

我遇到了问题,因为 Web 服务使用相同的类.为了同时使用这两种 webmethods,我在我的测试项目中添加了 2 个 webreferences.但是,依赖类有 2 个副本,具有不同的命名空间.作为短期修复,我正在编辑 VS 创建的类.

必须有更好的方法!预先感谢您的帮助.

解决方案

我不确定您如何(以及是否)可以修改 VS Web 参考向导的行为.

但是,您可以从命令行使用 wsdl.exe 或 svcutil.exe(取决于您希望 System.Web 还是 WCF 样式的客户端代理到您的服务)并为共享类型指定适当的选项.

对于wsdl.exe,你想要的命令行选项是/sharetypes,虽然我很多年没碰过它,所以我不记得确切的使用细节.

对于 svcutil.exe,您需要的命令行选项是/reference:.您可以在可以引用的程序集中拥有共享类.如果您可以访问的共享类的唯一定义是在两个服务的 WSDL 中,您可能需要使用 svcutil.exe 生成客户端代理,将其修剪为仅包含共享类并从中构建参考程序集用于两个服务的实际客户端代理.

这种方法的缺点是,如果其中一项服务的 WSDL 发生变化,您需要再次运行该工具.这可以通过向项目中的 BeforeBuild 目标添加一个自定义任务来缓解,该任务始终针对这两个服务运行该工具.

I have a web service project that has 2 asmx files. Let’s call them internal.asmx & external.asmx In practice, these have different clients:

Externally a client will call externalWS.PersistOrder(Order order ) and internally, we process the order internalWS ProcessOrder(Order order). Therefore the Order class is a shared dependency across these webservices.

I am writing a test application that calls different webmethods on both of these webservices.

I am having problems because the web services use the same classe. In order to use both webmethods, I am adding 2 webreferences to my test project. However, there are 2 copies of the dependant classes, with different namespaces. As a short term fix I am editing the classes that VS creates.

There has to be a better way! Thanks in advance for your help.

解决方案

I am not sure how (and if) you can modify the behavior of the VS web reference wizard.

You could, however, use wsdl.exe or svcutil.exe (depending on whether you want System.Web or WCF-style client proxy to your services) from the command line and specify the appropriate option for shared types.

For wsdl.exe the command line option you want is /sharetypes, though I haven't touched it in years, so I don't remember the exact usage details.

For svcutil.exe the command line option you want is /reference:. This you to have the shared class in an assembly you can reference. If the only definition of the shared class you can get to is in the WSDL of the two services, you might need to use svcutil.exe to generate client proxy, trim it down to contain the shared class only and build a reference assembly from it for the actual client proxies for the two services.

The drawback of this approach is that if the WSDL for one of the services change, you need to run the tool again. This can be mitigated by adding a custom task tot he BeforeBuild target in your project that runs the tool always against both services.

这篇关于在 .NET 项目中管理 2 个具有共享类依赖项的 Web 引用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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