简体   繁体   English

使用javascript(AJAX)进行双工WCF服务调用

[英]Duplex WCF Service call using javascript (AJAX)

Now i am working with WCF Rest Service 现在我正在使用WCF Rest Service

Now i am trying WCF Duplex Communication in WCF REST Service 现在我正在WCF REST服务中尝试WCF双工通信

Currently i am calling service through jquery AJAX and getting response back to it 目前,我正在通过jquery AJAX调用服务并获得响应

Like this: 像这样:

 $.ajax({
        type: varType, //GET or POST or PUT or DELETE verb
        url: varUrl, // Location of the service
        data: varData, //Data sent to server
        contentType: varContentType, // content type sent to server
        dataType: varDataType, //Expected data format from server
        processdata: varProcessData, //True or False
        crossDomain: true,
        cache: varCache,
        timeout: 200000,
        success:  function (response) {// When Service call success
                 var names = response.d;
                 alert(names);
             },
        error: function (xhr) {// When Service call fails
          alert(xhr.responseText);
        }
    });

But in duplex communication there is a call back contract in the service which service communicate later to the client. 但是在双工通信中,服务中有一个回叫合同,该服务随后与客户端通信。

How can i get the response of the call back contract in jquery ajax ? 我如何在jquery ajax中获得回拨合同的响应?

Also i have one doubt, Is webHttpbinding will support for Duplex communication ? 我也有一个疑问,webHttpbinding是否支持双工通信?

How can i get the response of the call back contract in jquery ajax ? 我如何在jquery ajax中获得回拨合同的响应?

IMHO to receive a call from your service to a client via HTTP SignalR should be used. 应该使用IMHO通过HTTP SignalR接收从您的服务到客户端的呼叫。 It uses push technology, long-pulling and other to allow this. 它使用推技术,长拉技术和其他技术来实现这一点。 Another way to do this would be to emulate this by repeatedly calling a service for changes. 做到这一点的另一种方法是通过反复调用服务进行更改来模拟这一点。

It seems hard to do it via WSDualHttpBinding which supports duplex communication. 通过支持双工通信的WSDualHttpBinding似乎很难做到这一点。 Please see a note by Juval Lowy in the "Programming WCF" book where he states for this binding: "Duplex callbacks are nonstandard, as there is no industry reference that states how the client endpoint address is passed to the service or how the service publishes the callback contract in the first place." 请参阅Juval Lowy在“ Programming WCF”一书中的注释,其中他指出了此绑定:“双工回调是非标准的,因为没有行业参考来说明如何将客户端端点地址传递给服务或该服务如何发布首先是回调合同。”

Also i have one doubt, Is webHttpbinding will support for Duplex communication ? 我也有一个疑问,webHttpbinding是否支持双工通信?

I believe it is not supported there. 我相信那里不支持它。 WebHttpBinding does not support sessions ( ReliableSession property) and this is required by the duplex communication (see System-Provided Bindings ). WebHttpBinding不支持会话( ReliableSession属性),而双工通信则需要此属性(请参阅系统提供的绑定 )。

And BTW WebHttpBinding is superseded by ASP.NET WebApi. BTW WebHttpBinding被ASP.NET WebApi取代。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM