【问题标题】:WCF works ONLY AsynchronouslyWCF 只能异步工作
【发布时间】:2017-03-31 12:53:00
【问题描述】:

我的 WebApplication 中有一个 WCF“MWManageSession”服务,所以我没有任何服务引用。 问题是它似乎只能异步工作而不是同步工作。

公共接口 IMWManageSession{

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

}

我在客户端函数上使用 wcf

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

}

当 wcf 正在工作时,我得到了执行代码“OnServiceSucceed”……

如何使 wcf 仅同步工作? 提前致谢!

【问题讨论】:

标签: asp.net .net wcf client asp.net-ajax


【解决方案1】:

也许你可以尝试添加到你的ajax帖子async: false

类似这样的:

$.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
});

【讨论】:

  • 你说的是 async: false,我相信。
  • Uppsss!小错误
  • 不!,我的意思是同步......我需要 wcf 同步工作......(虽然它必须工作同步工作异步!!!
  • 如果我添加“async:false” --> 我得到这个错误:由于对用户体验的负面影响,主线程上的请求同步 XMLHttpRequest 已被弃用。更多信息xhr.spec.whatwg.org
  • @S.A.当然,您会收到该警告,因为由于用户体验等原因不推荐同步调用。如果您必须“真正”同步调用,请不要介意该警告。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2017-12-28
  • 1970-01-01
  • 2018-04-01
  • 2020-02-06
相关资源
最近更新 更多