0

I have a WCF “MWManageSession” service inside my WebApplication so I don’t have any service reference. The problem is that seems to work only asynchronously instead of synchronously.

public interface IMWManageSession{

[OperationContract]
[WebInvoke(Method = "POST",
BodyStyle = WebMessageBodyStyle.WrappedRequest,
ResponseFormat = WebMessageFormat.Json)]
string SetIdSelezionato_SessionData(String[] pvalori, SessionNavigation pSN, long varpChangingAzienda);

}

I consume the wcf on a client function using

$.ajax({
    type: "POST",
    url: webMethod,
    data: jsonText,
    processData: false,
    contentType: "application/json; charset=utf-8",
    dataType: "json",
    success: function (msg) {
        ServiceSucceeded(msg, ptoPopup, DatixWCF, myvar);
    },
    error: ServiceFailed
});

function ServiceSucceeded(result, ptoPopup, DatixWCF, myvar) {
console.log("ServiceSucceeded: " + result);

}

I get execute code that I put on “OnServiceSucceed” while the wcf is steel working…

How can I make the wcf works ONLY synchronously? Thanks in advance !

S.A.
  • 21
  • 6
  • Its not WCF, its ajax which is Async here, refer async=false here http://stackoverflow.com/questions/133310/how-can-i-get-jquery-to-perform-a-synchronous-rather-than-asynchronous-ajax-re – Anil Mar 31 '17 at 12:59

1 Answers1

0

Maybe you can try to add to your ajax post async: false

Something like this:

$.ajax({
    type: "POST",
    url: webMethod,
    data: jsonText,
    processData: false,
    contentType: "application/json; charset=utf-8",
    dataType: "json",
    async: false,
    success: function (msg) {
        ServiceSucceeded(msg, ptoPopup, DatixWCF, myvar);
    },
    error: ServiceFailed
});
Developer90
  • 172
  • 1
  • 2
  • 11
  • You are saying async: false, I believe. – Anil Mar 31 '17 at 13:02
  • Uppsss!! little mistake – Developer90 Mar 31 '17 at 13:05
  • No!, i mean sync.. i need that the wcf works sync... (althought it must work sync works async !!! – S.A. Mar 31 '17 at 13:28
  • If i add " async:false," --> i Get this error: A request synchronous XMLHttpRequest on the main thread is deprecated because of the negative effects on the user experience. Further information http://xhr.spec.whatwg.org/ – S.A. Mar 31 '17 at 13:36
  • @S.A. of course you'll get that warning because sync call is not recommended because of user experience etc. If you have to "really" call that synchronously, don't mind that warning. – yakya Mar 31 '17 at 13:43
  • And that should be a warning, not an error as you said. – yakya Mar 31 '17 at 13:44
  • I get an error --> "ServiceFailed" function is executing. – S.A. Mar 31 '17 at 13:55
  • excuse me !!.. you are right.. It works!!, (I had made a change in endpoint). Thanks.!.. – S.A. Mar 31 '17 at 14:21