从JavaScript WCF服务方法+同步调用 [英] WCF Service methods + Synchronous calls from javascript

查看:141
本文介绍了从JavaScript WCF服务方法+同步调用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我写了一个WCF服务,我试图调用服务方法的脚本在我的ASPX页面。

I have written a WCF service and am trying to call the service methods in a script in my ASPX page.

例如:

<script language="javascript" type="text/javascript">

<!--

        function Test() {
          **// The following call is an Async call.  
          tempuri.org.IService.GetData(1,OnRequestComplete, OnError, "");**
        }

        function OnRequestComplete(result, state) {
            var textBox = $get("txtInput");
            textBox.value = result;

        }
        function OnError(result) {
            var textBox = $get("txtInput");
            textBox.value = result;
        }

    //-->    
</script>

我要的是能够调用的服务方法同步

What I want is to be able to call the service method "synchronously"

例如: VAR的结果= tempuri.org.IService.GetData(1);

这可能吗?

推荐答案

我相信有没有能力在Javascript中做同步调用 - 总是返回在等待远程响应AJAX库。

I believe there's no ability to do synchronous calls in Javascript - the AJAX libraries will always return while waiting for a remote response.

你能解释一下你为什么要这么做?

Can you explain why you want to do this?

编辑:

在回答,你应该使用这个方法:

In answer, you should use this method:

  • 在onclick事件处理程序的形式提交按钮:使Web服务验证调用,并立即返回false(这样的形式不提交)。 这将是显示给用户的确证类型的消息是一个好主意,让他们知道这里发生了什么。

如果你得到一个有效的响应,然后用 document.form.submit(); 的形式提交到服务器。

If you get a valid response, then use document.form.submit(); to submit the form to the server.

这篇关于从JavaScript WCF服务方法+同步调用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆