通过 Web 服务发送 Linq to SQL 类
我有一个 Windows 应用程序和一个 Web 服务。两者都有一个带有 Customer 表的 Linq to SQL 映射器。来自同一个数据库的同一张表,一切都相同。我尝试将 winapp.Customer 对象发送到 Web 服务,但 webserviceReference.MyMethod() 接受 webservice.Customer 对象并且不接受 winapp.Customer 作为参数。尝试将 winapp.Customer 转换为 webservice.Customer 但也不起作用。有办法做到这一点吗?
I have a windows application and a web service. Both have a Linq to SQL mapper with Customer table on them. Same table from the same database, same everything. I tried to send winapp.Customer object to web service but the webserviceReference.MyMethod() accepts webservice.Customer object and doesn't accept winapp.Customer as parameter. Tried to cast winapp.Customer to webservice.Customer but didn't work either. Is there a way to accomplish this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
不,无法使用 ASMX Web 服务来完成此操作。它们要求代理类型和真实类型是不同的类型。
您可以使用 WCF 来完成此任务,尽管它打破了 SOA 的理念(客户端和服务器将通过公共类代码捆绑在一起)。
最后,使用任何类型的 Web 服务将 LINQ 传递到 SQL 或实体框架类都存在问题。当在层之间传递时,微软会搞乱并序列化依赖于实现的数据。当各层位于同一台计算机上时,这可能有意义,但当它们位于不同的计算机上时,意义就小得多。
No, there is no way to accomplish this using ASMX web services. They require that the proxy type and the real type be different types.
You can accomplish this using WCF, though it breaks the idea of SOA (the client and server will be tied together by the common class code).
Finally, there are problems with passing LINQ to SQL or Entity Framework classes using web services of any kind. Microsoft messed up and serializes implementation-dependent data when passing between tiers. This may make sense when the tiers are on the same computer, but makes much less sense when they are on different machines.
在您的 WinApp 中,您可能必须编写从 winapp.Customer 到 webservice.Customer 的显式转换。
In your WinApp, you'll probably have to write an explicit conversion from winapp.Customer to webservice.Customer.