none
WCF inside main web application works ONLY asyncronously RRS feed

  • Question

  • Hi,

    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 !

    Friday, March 31, 2017 12:42 PM

All replies

  • I add "

    async: false" but is deprecated --> so i get the error A request synchronous XMLHttpRequest on the main thread is deprecated because of the negative effects on the user experience. Further information xhr.spec.whatwg.org.

    Any suggestion ? another way to call WCF ?

    Friday, March 31, 2017 2:06 PM
  • >>How can I make the wcf works ONLY synchronously?

    For your scenario, WCF works synchronously. The async is caused by Ajax request.

    >>async: false" but is deprecated

    As of jQuery 1.8, the use of async: false with jqXHR ($.Deferred) is deprecated; you must use the success/error/complete callback options instead of the corresponding methods of the jqXHR object such as jqXHR.done().

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

    Could you share us the implementation of SetIdSelezionato_SessionData? Which value did you get on ServiceSucceeded function? Did you get the expected return value for SetIdSelezionato_SessionData?

    In addition, if you want to use jQuery to send sync request, I suggest you use jQuery version earlier than 1.8.

    # jQuery 1.7.2

    https://www.nuget.org/packages/jQuery/1.7.2


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Monday, April 3, 2017 2:09 AM
  • WCF calls are synchronous by default, although they can be configured to be asynchronous. From the jQuery documentation:

    By default, all requests are sent asynchronously (i.e. this is set to true by default). If you need synchronous requests, set this option to false. Cross-domain requests and dataType: "jsonp"requests do not support synchronous operation. Note that synchronous requests may temporarily lock the browser, disabling any actions while the request is active. As of jQuery 1.8, the use of async: false with jqXHR ($.Deferred) is deprecated; you must use the success/error/complete callback options instead of the corresponding methods of the jqXHR object such as jqXHR.done().

    You should use local call back functions passing in jqXHR object and HTTP status.

    Example

    $.ajax({
            type: "POST",
            url: webMethod,
            data: jsonText,
            processData: false,
            contentType: "application/json; charset=utf-8",
            dataType: "json",
            success: function (data, status, jqXHR) {
    		},
    		error: function (jqXHR, status, err) {
    		},
    		complete: function (jqXHR, status) {
    		}
        });


    william xifaras


    Monday, April 3, 2017 3:10 PM