通过 Internet 使用 WCF/WPF 实现类型保真度

发布于 2024-08-02 10:47:51 字数 378 浏览 4 评论 0原文

我们正在尝试提出一种架构方法来设计应用程序,其中前端作为基于浏览器的 xaml 应用程序运行。

这个应用程序联系使用WCF构建的Web服务器上的服务,WCF服务主机域模型使用nhibernate进行持久化(因此它通过使用列表和集合等接口来感知Hibernate)

我知道当使用soap Web服务时,只有模式是共享的,而不是类型,但我们希望共享类型,因为类型将具有方法、业务逻辑等..

并且由于通信的两端都在我们的控制之下,我们实际上并不需要使用soap,但对于所有清晰性和调试性、安全性和普遍的安心感,SOAP 是人们所期望的。

想知道如果这是人们使用的方法,以及是否有任何框架可以启用/指导/简化将代理转换回原始类型的任务..

或者是否有任何其他可能的方法。

We are trying to come up with an architecture approach for designing an application where front end runs as a browser based xaml app.

this app contacts services on the web server that are built using wcf, the wcf services host domain model that uses nhibernate for persistence (so it is hibernate aware by using interfaces for lists and sets and such)

i understand that when using soap web services, only schema are shared and not types, but we would like to share types since types would have methods, business logic etc ..

and since both ends of communication are in our control, we don't really need to use soap, but for all clarity and debugging, security and general peace of mind, SOAP is desired.

wondering what if this is an approach people use, and if there are any frameworks out there that enable/guide/ease the task of converting proxies back to their original types..

or if there are any other approaches possible.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

夏九 2024-08-09 10:47:51

Marc 是正确的,您不能在 SOA 架构中共享类型。事实上,在SOA中,这是不可取的。

但您已经决定不需要 SOA,因此您可以根据需要共享类型。只需在使用“添加服务引用”时单击“高级”按钮,然后选择要在客户端和服务之间共享的类型集。

当然,这确实将您的客户端和服务紧密地绑定在一起,并失去了 SOA 的其他好处,但这并不比您使用 COM 更糟糕。

Marc is correct that you cannot share types in an SOA architecture. In fact, in SOA, it is undesirable.

But you've decided you don't need SOA, so you can share types if you like. Just click the "Advanced" button when you use "Add Service Reference", and choose the set of types you want shared between the client and service.

Of course, this does bind your client and service tightly together, and loses other benefits of SOA, but it's no worse than if you were using COM.

夜血缘 2024-08-09 10:47:51

在真正的 SOA 世界中,您不能共享类型(例如类) - 因为最终,它真正归结为所有内容都被序列化为 XML 流并通过网络发送。另外,一端可能是 .NET,另一端可能是 PHP 或 Java,现在我认为您的 Java 客户端无法理解并能够在您的对象上执行 .NET 方法。

SOA 与“对象远程处理”不同 - 它只是不适合通过网络实际远程处理对象 - 它发送 XML 消息 - 这就是它所能做的。它可以来回发送数据,但不能发送代码。

如果在您的场景中,您确实控制了对话的两端,那么您当然可以将所有业务对象打包到一个(或多个)共享程序集中,然后在服务器和客户端之间物理共享这些程序集。在这种情况下,您可以在服务器上序列化对象“Customer”,发送 XML 消息,然后在客户端再次将其反序列化为“Customer”。但请注意:您发送的只是客户的状态 - 其字段和属性中的值。您并没有真正发送代码 - 只是恰好在线的两端都可用。

在这种情况下,很多人所做的是将感兴趣的信息从实际的“客户”对象中提取到通常称为“CustomerDTO”的“数据传输对象”中,例如使用 AutoMapper 为了使其更容易,然后他们在线路的另一端创建一个新的 Customer 实例并将数据从 DTO 复制回来进入“真实”的物体。

马克

You CANNOT share types (e.g. classes) in a true SOA world - because in the end, what it really comes down to is everything is serialized into a XML stream and sent across the wire. Also - one end could be .NET and the other end PHP or Java - now I don't think your Java client will understand and be able to execute .NET methods on your object.

SOA is a different beast than "object remoting" - it just doesn't lend itself to actually remoting objects across the wire - it sends XML messages across - that's all it can do. It can send data back and forth, but not code.

If in your scenario you do control both ends of the conversation, of course what is available to you is the ability to package all your business objects into a shared assembly (or several), and then physically share those assemblies between your server and client. In this case, you could serialize an object "Customer" on the server, send the XML message across, and on the client side, deserialize it into a "Customer" again. But be aware : all you're sending across is the state of Customer - the values in its fields and properties. You're not really sending the code across - that just happens to be available on both ends of the wire.

What a lot of folks do in this case is extracting the information of interest from the actual "Customer" object into a "Data-Transfer Object" often called "CustomerDTO", by using e.g. something like AutoMapper in order to make it easier, and then they create a new Customer instance on the other end of the wire and copy the data back from the DTO into the "real" object.

Marc

素手挽清风 2024-08-09 10:47:51

有一种简单的方法可以在客户端和服务之间共享类型,只需在添加服务引用之前向客户端添加对共享类型程序集的引用即可。

您可以在那里找到详细的场景和示例项目:

http://blog.walteralmeida.com/2010/08/wcf-tips-and-tricks-share-types- Between-server-and-client.html

There is an easy way to share types between client and service, just by adding reference to shared type assembly to your client BEFORE adding the service reference.

You can find the detailed scenario and sample project there:

http://blog.walteralmeida.com/2010/08/wcf-tips-and-tricks-share-types-between-server-and-client.html

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文