WCF& ASP.NET:使用 AJAX 的双工支持

发布于 2024-07-25 10:12:32 字数 890 浏览 7 评论 0原文

我知道 WSDualHttpBinding、NetTcpBinding 和 NetPeerTcpBinding 绑定都支持双工/回调服务操作。

我在互联网上找不到任何人询问 ajax 调用是否支持双工。 也许我无法找到任何相关内容的原因是因为我完全误解了一些关键的 WCF 概念,这使得这个问题成为最愚蠢的问题......

我知道 webHttpBinding 绑定与 一起使用。 生成客户端代理对象所需的js。

这是否不可能,因为双工服务需要托管回调服务,而客户端无法做到这一点? (如果这是有道理的..)

我的应用程序分层如下:
1. WebSite1 - ajax 调用 WebSite1.MyClientService。
2. WebSite1.MyClientService - 引用 MyServiceProxies DLL 的 WCF 自托管服务。
3. MyServiceProxies DLL - 继承自 ClientBase 的自定义代理(用于代替“添加服务引用”自动生成的代理)。 这只是将实际服务调用委托给 [MyService : IMyService at WinService WCF Host EXE] 处的 base.Channel.OperationName()。
4. WinService WCF Host EXE - 它作为 Windows 服务作为单例运行,允许多线程调用。 来自 WebSite1 的调用查询该单例保存的内存中值。 该单例最终将通过单独的数据层将内存中保存的所有数据提交到数据库。

WinService 配置为通过 net.tcp 使用双工调用。 WinService 将与 WebSite1 IIS 应用程序在同一台计算机上运行。

I know that WSDualHttpBinding, NetTcpBinding, and NetPeerTcpBinding bindings all support duplex/callback service operations.

I can't find anywhere on the internet anyone even asking if duplex is somehow supported for ajax calls. Maybe the reason for my inability to find anything on this is because I am completely misunderstanding some key WCF concept that makes the question the dumbest question there is...

I know that the webHttpBinding binding along with <enableWebScript/> gneerates the js necessary for proxy objects client-side.

Is this impossible because duplex services need that callbackservice to be hosted and there is no way to do that client-side ? (If that makes sense..)

My app is layered as follows:
1. WebSite1 - ajax calls to WebSite1.MyClientService.
2. WebSite1.MyClientService - WCF Self-hosted service that references MyServiceProxies DLL.
3. MyServiceProxies DLL - Custom proxies (used instead of "Add Service reference" auto-generated proxies) that inherit from ClientBase. This simply delegates actual service calls out to base.Channel.OperationName() at [MyService : IMyService at WinService WCF Host EXE].
4. WinService WCF Host EXE - This is running as a windows service, as a singleton, allowing multi-threaded calls. The calls from WebSite1 query the in-memory values held by this singleton. This singleton will eventually commit all data held in-memory to database via seperate data layer.

The WinService is configured to use duplex calls over net.tcp. The WinService will run on same machine as WebSite1 IIS App.

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

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

发布评论

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

评论(1

淡笑忘祈一世凡恋 2024-08-01 10:12:32

我在互联网上找不到任何地方
有人甚至问是否是双工
以某种方式支持ajax调用。
也许是我无法做到的原因
在这方面找到任何东西是因为我是
完全误解了一些关键
提出问题的 WCF 概念
最愚蠢的问题是......

也许并不愚蠢,因为我认为你不理解的是 AJAX,而不是 WCF。

在 AJAX 中拥有双工合约实际上没有意义。 双工合约必须期望服务器随时调用合约操作。 例如,它不像发布/订阅或请求响应,在消息开始到达之前,客户端必须执行操作。 通过双工合约,消息可以随时到达。

谁会听他们的? 不是浏览器。 如果浏览器要对来自某些远程计算机的未经请求的消息做出反应,然后运行代码 - 嗯,这听起来很像病毒的定义,不是吗?

我认为在相当长的一段时间内你都不会在 JavaScript 中找到对双工合约的支持。

I can't find anywhere on the internet
anyone even asking if duplex is
somehow supported for ajax calls.
Maybe the reason for my inability to
find anything on this is because I am
completely misunderstanding some key
WCF concept that makes the question
the dumbest question there is...

Not dumb, maybe, because I think it's AJAX you don't understand, not WCF.

It doesn't really make sense to have a duplex contract in AJAX. A duplex contract has to expect the server to call the contract operations at any time. It's not like publish/subscribe, for instance, or solicit response, where an action by the client is necessary before messages start arriving. With a duplex contract, messages could arrive at any time.

Who's going to listen to them? Not the browser. If the browser were going to react to unsolicited messages coming in from some remote machine and then running code - well, that sounds a lot like the definition of a virus, doesn't it?

I don't think you're going to find support for duplex contracts in JavaScript for quite some time.

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