是否有相当于 RPC 上下文句柄的 WCF?

发布于 2024-07-22 20:53:59 字数 466 浏览 4 评论 0原文

我正在更新旧的 C++ 服务以使用 WCF 而不是 RPC,并且存在发送和接收句柄时使用什么类型的问题(HANDLE、void*..等)。 在更新的服务中,我目前使用 IntPtr,但是当从服务的 64 位版本转换为 32 位版本时,这不起作用。 IntPtr 无法反序列化,因为在内部它只是一个 void*,根据您运行的环境而有所不同。

这解决了问题,因为 RPC 基础结构从不实际发送句柄值,而是引用句柄的 GUID。 以下文章介绍了此过程:

请参阅上下文句柄部分

我正在寻找与此功能等效的 WCF。 我可以自己在服务上编写类似的逻辑来执行此操作,甚至只需将 IntPtr 更改为 Int64,但我希望有类似于 RPC 方式的东西。

I'm updating an old C++ service to use WCF instead of RPC and there is an issue as to what type to use when sending and receiving a handle (HANDLE, void*..etc). In the updated service I currently have it using IntPtr, but this does not work when going from a 64 bit version of the service to a 32 bit version. The IntPtr can not deserialize because internally it is just a void* which will be different depending on which environment you run in.

This solves the problem because the RPC infrastructure never actually sends the handle value, rather a GUID that references the handle. This process is described in the following article:

See Context handles section

I'm looking for a WCF equivalent to this functionality. I could write similar logic myself on the service to do this, or even just change the IntPtr to a Int64, but I'm hoping there is something similar to RPC way.

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

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

发布评论

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

评论(1

耳根太软 2024-07-29 20:53:59

我建议您重新设计这样的代码。 传递句柄的最初原因可能不再有效。

另外,我假设您在本机客户端和服务器之间传递句柄,但使用 WCF 您将使用托管代码。 一侧的托管代码将如何处理另一侧的“句柄”? 例如,将文件路径发送到另一端并让另一端打开文件,而不是传递文件句柄,可能更有意义。

这段代码可能是在 RPC 还不是一项旧技术的时候创建的。 这表明它的其余部分也是采用与 RPC 当代的技术设计的。 整个应用程序很可能需要针对现代世界重新设计。 在重新设计中,您可能会使用 WCF 来完成当前使用 RPC 所完成的相同种类的事情; 但这不会是一对一的比赛。

I recommend that you redesign any code like this. The original reason for passing handles around may no longer be valid.

Also, I presume you were passing handles around between native clients and servers, but with WCF you'll be working with managed code. What will the managed code on one side be doing with the "handle" from the other? It may make more sense, for instance, to send a file path to the other side and let the other side open the file, rather than passing a file handle.

This code was probably created at a time when RPC was not an old technology. This suggests that the rest of it was also designed with technologies contemporary to RPC. It's quite likely that the entire application may need to be redesigned for the modern world. In that redesign, you will likely be using WCF to do the same kind of thing that is currently being done using RPC; but it won't be a one to one match.

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