如何使用JS同步调用WCF中得方法。获取返回值的问题

解决方案 »

  1.   

    http://www.cnblogs.com/chengfeng_sue/archive/2008/12/26/1363347.html
      

  2.   

    http://social.microsoft.com/Forums/zh-CN/wcfzhchs/thread/eea2f842-f79e-450c-b114-9fb87b4aaa04
      

  3.   

    你有没有这方面的例子。能给发一个吗?
    270281544*qq.com
      

  4.   

    上面的就是例子,你只需要把 异步请求的参数 从true 改为false 就是同步了但我建议你还是异步好一些
      

  5.   

    我现在就是异步调用。但是我遇到在一个使用JS循环调用WCF里面的方法的时候,就会出现问题了?所以我想找个同步调用的示例。
      

  6.   

    我现在是这样写的
            function GetMenuNavigation() {
                var MenuNavigationID = "1";            var proxy = new Navigation.INavigation();
                proxy.GetLeftMenuNavigationList(MenuNavigationID, Succeeded);
            }        function Succeeded(Result) {           //处理结果集合        }
    我想这样写,直接接受到返回值,
    function GetMenuNavigation() {
                var MenuNavigationID = "1";            var proxy = new Navigation.INavigation();
                var Result = proxy.GetLeftMenuNavigationList(MenuNavigationID);
                //我想直接处理结果集合,让这个方法返回值后再继续往下执行。
            }
      

  7.   

    GetLeftMenuNavigationList 这个方法里的代码贴下
      

  8.   

    这个方法是通过WCF的服务里面的方法
    配置文件<?xml version="1.0"?>
    <configuration>
        <system.serviceModel>
            <behaviors>
                <serviceBehaviors>
                    <behavior name="WebBehavior">
                        <!--httpGetEnabled - 指示是否发布服务元数据以便使用 HTTP/GET 请求进行检索,如果发布 WSDL,则为 true,否则为 false,默认值为 false-->
                        <serviceMetadata httpGetEnabled="true" />
                      
                    </behavior>
                  
                </serviceBehaviors>
                <endpointBehaviors>
                    <behavior name="NavigationBehavior">
                        <!--enableWebScript - 启用 WCF 服务的 脚本 编程模型-->
                        <enableWebScript />
                    </behavior>
                </endpointBehaviors>
            </behaviors>
            <services>
                <!--name - 提供服务的类名-->
                <!--behaviorConfiguration - 指定相关的服务行为配置-->
                <service name="RTERP.Services.SYSManage.NavigationService" behaviorConfiguration="WebBehavior" >
                    <!--address - 服务地址-->
                    <!--binding - 通信方式-->
                    <!--contract - 服务契约-->
                    <!--behaviorConfiguration - 指定相关的端点行为配置-->
                    <endpoint address="" binding="webHttpBinding" contract="RTERP.Contract.SYSManage.INavigation" behaviorConfiguration="NavigationBehavior" />
                </service>
              
            </services>
        </system.serviceModel>
    </configuration>服务文件里面的内容
    <%@ ServiceHost Language="C#" Debug="true" Service="RTERP.Services.SYSManage.NavigationService" Factory="System.ServiceModel.Activation.WebScriptServiceHostFactory"  %>服务接口using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using RTERP.Domain.SYSManage;
    using System.ServiceModel;
    using System.ServiceModel.Web;
    using RTERP.Domain;namespace RTERP.Contract.SYSManage
    {
        [ServiceContract(Namespace = "Navigation")]
        public interface INavigation
        {
            /// <summary>
            /// 
            /// </summary>
            /// <param name="FatherNavigationID"></param>
            /// <returns></returns>
            [OperationContract]
            IList<Navigation> GetNavigationList(string FatherNavigationID);        /// <summary>
            /// 
            /// </summary>
            /// <param name="FatherNavigationID"></param>
            /// <returns></returns>
            [OperationContract]
            string  GetLeftMenuNavigationList(string FatherNavigationID);    }
    }
    服务using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using RTERP.Domain.SYSManage;
    using RTERP.Persistence.SYSManage;
    using RTERP.Contract.SYSManage;
    using RTERP.Domain;namespace RTERP.Services.SYSManage
    {
        public class NavigationService : INavigation
        {
            NavigationDao _NavigationDao = new NavigationDao();
            public IList<Navigation> GetNavigationList(string FatherNavigationID)
            {
                return _NavigationDao.GetNavigationList(FatherNavigationID);
            }        public string GetLeftMenuNavigationList(string FatherNavigationID)
            {
                StringBuilder sb = new StringBuilder();            //访问数据库
                //拼接导航字符串
                   
                return sb.ToString();        }
           
        }
    }
      

  9.   

    我把问题想简单了,js不支持多线程,想同步调用WCF很困难。你可以这样做,就是用js 创建一个队列,先将需要循环的请求入列。然后让第一个任务 出列 并处理。之后 在每个任务的回调函数中对队列做出队操作。用队列来实现同步的功能。