ASMX对象->代理对象转换 [英] ASMX Object -> Proxy Object Conversion

查看:45
本文介绍了ASMX对象->代理对象转换的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以将对象的实例转换为相同类型的Web服务代理的实例?

Is there a way to convert an instance of an object to an instance of a web service proxy of the same type?

.NET似乎必须具备这种功能,因此我只是在尝试查找并重新使用此功能.

It seems like this is something .NET has to be capable of under the hood, so I'm just trying to find and re-use this function.

这肯定有点尴尬,但是我可以通过一个公共库访问我项目中的两种类型,对于我来说,能够使用真实对象,然后将其转换为代理,这将非常方便.在调用Web服务之前的最后一分钟键入.

It's definitely a little awkward, but I have access to both types in my project through a common library, and it would be very convenient for my purposes to be able to work with the real object, and then convert it to the proxy type at the last minute before invoking the web service.

由于我确定有人会问-我有可能切换到WCF客户端,但是该服务是ASMX,并且不太可能很快改变.

Since I'm sure someone will ask - I can potentially switch to a WCF client, but the service is ASMX, and that isn't likely to change any time soon.

我已经尝试过尝试生成可重复使用该类型的WCF客户端,并且该客户端对于WCF服务正常运行,但似乎不适用于ASMX服务.

I've already tried experimented with trying to generate a WCF client that will re-use the type, and it works fine for WCF services, but doesn't seem to work with ASMX services.

推荐答案

我最近将Automapper用于此类操作.对于将Web服务代理映射到DTO等非常有用.可以在此处找到该项目,并提供一些示例如何使用它.

I have recently used Automapper for this type of operation. It is very useful for mapping Web Service proxies to DTO etc. The project can be found here with some examples of how to use it.

这篇关于ASMX对象->代理对象转换的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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