简体   繁体   中英

Duplex WCF Service call using javascript (AJAX)

Now i am working with WCF Rest Service

Now i am trying WCF Duplex Communication in WCF REST Service

Currently i am calling service through jquery AJAX and getting response back to it

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 ?

Also i have one doubt, Is webHttpbinding will support for Duplex communication ?

How can i get the response of the call back contract in jquery ajax ?

IMHO to receive a call from your service to a client via HTTP SignalR should be used. 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. 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."

Also i have one doubt, Is webHttpbinding will support for Duplex communication ?

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 ).

And BTW WebHttpBinding is superseded by ASP.NET WebApi.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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