直接通过 DLL 使用 Web 服务类型
我有一个带有返回类型(foo)的函数的网络服务。如果我通过 2.0 生成的代理在 .NET 中使用此 Web 服务,它会在生成的代理中创建一个名为 foo 的类。如果我有包含 Web 服务使用的 DLL 的类 (foo) 的 DLL,有没有办法让它使用该类而不是创建自定义代理类?我正在寻找类似于远程处理的功能......但不是远程处理。
I have a webservice with a function that returns a type (foo). If I consume this webservice in .NET through the 2.0 generated proxies, it creates a class called foo in the generated proxy. If I have the DLL that contains that class (foo) that is the DLL being used by the webservice, is there any way to have it use that class instead of creating a custom proxy class? I'm looking for something similar to what remoting does... but not remoting.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我见过 3 种方法:
创建代理的深层副本
物体变成“真实”物体
反射。有效,但是当然
参考
带有数据契约的 dll(您的
数据类)并使用它们来代替
通过代码创建任何代理
一代。
I've seen 3 ways of doing this:
creates deep copies of your proxy
objects into the "real" objects by
reflection. Works, but of course
with a little performance offtrade
dll with the data contracts (your
data classes) and use them instead
of creating any proxy by code
generation.
我认为这里的关键问题是生成代理。我通常使用两种不同的 Web 服务方法:
1) 传统服务,您公开方法,客户端在 Visual Studio 中生成代理来使用这些方法。
2) 请求/响应服务,其中公开的“服务”更多的是传递,并且正在执行的“操作”被封装在发送到服务和从服务接收的对象中。这些操作将位于服务器和客户端都拥有的共享库中。
在前者中,我经常遇到同样的问题,而且我真的不认为有解决方案,至少没有 Visual Studio 会喜欢的解决方案。您也许可以手动修改生成的代理以使用其他类,但是每次重新生成时都必须重复该步骤。相反,您可以在 Visual Studio 之外生成类似 CodeSmith 的内容(旧版本是免费的,但取决于.NET 1.1),这将需要一些工作来为代理创建模板,并在需要更新代理时跳出 IDE 重新生成。
不过,我可以为后者推荐一个很好的工具,那就是 Agatha 项目。它采用将“服务”与正在执行的“操作”分离的方法,并使共享库的方法变得非常简单。根据您的日程安排,这样的重新架构对于您正在从事的项目来说很可能是不可能的,但这绝对是未来项目值得探索的事情。
I think the key issue here is in generating the proxies. I've generally used two different approaches to web services:
1) Traditional services, where you expose methods and a client generates the proxy in Visual Studio to consume the methods.
2) Request/Response services, where the exposed "service" is more of a pass-through and the "actions" being performed are encapsulated in the objects being sent to and received from the service. These actions would be in that shared library that both the server and the client have.
In the former I often run into this same problem and I don't really think there's a solution, at least not one that Visual Studio is going to like at all. You could perhaps manually modify the generated proxies to use the other classes, but then you'll have to repeat that step any time you re-generate. Conversely, you can generate outside of Visual Studio in something like CodeSmith (the older version is free, but depends on .NET 1.1), which will require some work to create a template for the proxies and to step outside the IDE to re-generate any time you need to update them.
I can recommend a good tool for the latter, however, and that would be the Agatha project. It takes the approach of separating the "service" from the "actions" that are being performed, and makes the approach of the shared library very easy. Such a re-architecture may very well be out of the question for the project you're working on depending on your schedule, but it's definitely something to explore for future projects.
您可以编写自己的代理类,也可以在 Foo 类上实现一个构造函数,该构造函数采用生成的 Foo 类的实例并根据需要复制数据。
You could write your own proxy class, or you could implement a constructor on your Foo class that takes an instance of the generated Foo class and copies over the data as appropriate.