• .net Ajax系列(2)调用多Web Service


     

    scriptManager的多服务调用和ScriptManagerProxy调用WebService

    1)  母版页

    添加母版页,并向页添加ScriptManager,为它添加2ws引用(多服务引用)

    <asp:ScriptManager ID="ScriptManager1" runat="server">

            <Services>

                <asp:ServiceReference Path="selfWS.asmx" />

                <asp:ServiceReference Path="ThirdWs.asmx" />

            </Services>

    </asp:ScriptManager>

     

    两个WS如下:

    [ScriptService]

    public class selfWS : System.Web.Services.WebService {

    [WebMethod]

    public string ShowName(string s)

    {

            return "This's your name:" + s;

    }

    }

    //=======================================================

    [ScriptService]

    public class ThirdWs : System.Web.Services.WebService {

        [WebMethod]

        public string HelloWorld() {

            return "the third ws showing";

        }

    }

    2)   母版页添加对两个WS的方法调用。

    <input type="button" value="MasterClick" onclick="showName()" />

    <input type="button" value="ThirdClick" onclick="showThird()" />

     

    <script>

            function showName()

            {

                selfWS.ShowName("master",showww);

            }

            function showww(result)

            {

                alert(result);

            }

           

            function showThird()

            {

                ThirdWs.HelloWorld(

                function success(result)

                {

                    alert(result);

                }

                );

            }

    </script>

    3)   新加子页,启用这个母版

    点击2个按钮,测试完成。

    4)   在这个子页中添加ScriptManagerProxy,同时为其添加对另一个WS的引用

    <asp:ScriptManagerProxy ID="ScriptManagerProxy1" runat="server">

        <Services>

            <asp:ServiceReference Path="SelfWSs.asmx" />

        </Services>

    </asp:ScriptManagerProxy>

    WS的内容如下:

    [ScriptService]

    public class SelfWSs : System.Web.Services.WebService {

        [WebMethod]

        public string ShowNamess(string str1,string str2)

        {

            return "this is no Master Name:"+str1+str2;

        }

    }

    5)   预览完成。

    备注:此示例有以下几个点:

    母版页(或ScriptManager)对多个WS的引用并调用它们的方法;

    对已经启动带有ScriptManager的母版页的子页来说,如果调用其它WS的方法;

    调用WS的参数问题。

    博客园大道至简

    http://www.cnblogs.com/jams742003/

    转载请注明:博客园

  • 相关阅读:
    执行truncate引发ORA-02266的问题分析
    一文搞懂MySQL-8.0 redo优化
    写给迷茫中的大一大二的学弟学妹,学渣逆袭中的个人经历与心得
    99+好友共同关注,公众号推荐
    Cesium
    Cesium
    Cesium
    Cesium
    虚拟化学习笔记-KVM虚拟化跨机迁移原理
    虚拟化学习笔记-KVM虚拟化跨机迁移原理
  • 原文地址:https://www.cnblogs.com/jams742003/p/1584407.html
Copyright © 2020-2023  润新知