用户操作
[即时聊天] [发私信] [加为好友]
ZPTID:IamBird
28195次访问,排名4422,好友0人,关注者0人。
IamBird的文章
原创 35 篇
翻译 0 篇
转载 18 篇
评论 8 篇
ZPT的公告
最近评论
dddfffddff123:那这样的话服务器主机就要支持.NET咯,是不是啊?
这样对服务器要求挺高的呀。
wszhoho:这些代码你真的测试过吗,我测试了第一种就失败了。
fmfeggman:兄弟 我试了你的方法好想不行
url=http://localhost:1323/WebSite6/Service.asmx/方法名;
url会报错
宽带用户:谁有权制定法律?只有议会
阿标:好文章!
文章分类
收藏
    相册
    asp.net
    我同事非说这个网赚很灵,陪她玩一下试试
    存档
    软件项目交易
    订阅我的博客
    XML聚合  FeedSky
    订阅到鲜果
    订阅到Google
    订阅到抓虾
    订阅到BlogLines
    订阅到Yahoo
    订阅到GouGou
    订阅到飞鸽
    订阅到Rojo
    订阅到newsgator
    订阅到netvibes

    转载 [转]:Javascript+xmlhttp调用Webservice收藏

    新一篇: 无限级分类在DataGrid和DropDownList中的体现 | 旧一篇: 网页常用小技巧(JavaScript)

    原文地址:http://netboy.cnblogs.com/archive/2006/02/18/333260.html

    1.  创建webservice,为了免于落俗我稍稍修改了创建webserice的默认webmethod。^_^
    using System;
    using System.Web;
    using System.Web.Services;
    using System.Web.Services.Protocols;

    [WebService(Namespace = "http://tempuri.org/")]
    [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
    public class Service : System.Web.Services.WebService
    {
        public Service () {

            //Uncomment the following line if using designed components
            //InitializeComponent();
        }

        [WebMethod]
        public string SayHelloTo(string Name) {
            return "Hello "+Name;
        }
       
    }
    还是俗了点。:)

    2. js调用webservice+xmlhttp的实现部分。

    <html>
    <title>
    Call webservice with javascript and xmlhttp.
    </title>
    <body>
    <script language="javascript">

    //Test function with get method.
    function RequestByGet(data){

    var xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
    //Webservice location.
    var URL="http://localhost:1323/WebSite6/Service.asmx/SayHelloTo?Name=Zach";
    xmlhttp.Open("GET",URL, false);
    xmlhttp.SetRequestHeader ("Content-Type","text/xml; charset=utf-8");
    xmlhttp.SetRequestHeader ("SOAPAction","http://tempuri.org/SayHelloTo");
    xmlhttp.Send(data);
    var result = xmlhttp.status;
    //OK
    if(result==200) {
    document.write(xmlhttp.responseText);
    }
    xmlhttp = null;
    }

    //Test function with post method
    function RequestByPost(value)
    {
    var data;
    data = '<?xml version="1.0" encoding="utf-8"?>';
    data = data + '<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">';
    data = data + '<soap:Body>';
    data = data + '<SayHelloTo xmlns="http://tempuri.org/">';
    data = data + '<Name>'+value+'</Name>';
    data = data + '</SayHelloTo>';
    data = data + '</soap:Body>';
    data = data + '</soap:Envelope>';

    var xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
    var URL="http://localhost:1323/WebSite6/Service.asmx";
    xmlhttp.Open("POST",URL, false);
    xmlhttp.SetRequestHeader ("Content-Type","text/xml; charset=gb2312");
    xmlhttp.SetRequestHeader ("SOAPAction","http://tempuri.org/SayHelloTo");
    xmlhttp.Send(data);
    document.write( xmlhttp.responseText);

    }

    </Script>

    <input type="button" value="CallWebserviceByGet" onClick="RequestByGet(null)">
    <input type="button" value="CallWebserviceByPost" onClick="RequestByPost('Zach')">

    </body>
    </html>
    对于使用post方法需要发送的那堆东东可以在webservice的测试页面中找到,自己拼凑加上对应的参数就可以。

    我发现用post方法的时候响应很慢,是因为用Post方法时发送的数据多的原因吗?

    发表于 @ 2006年05月15日 14:37:00|评论(loading...)|编辑

    新一篇: 无限级分类在DataGrid和DropDownList中的体现 | 旧一篇: 网页常用小技巧(JavaScript)

    评论

    #fmfeggman 发表于2007-07-08 16:34:03  IP: 218.77.187.*
    兄弟 我试了你的方法好想不行
    url=http://localhost:1323/WebSite6/Service.asmx/方法名;
    url会报错
    发表评论  


    当前用户设置只有注册用户才能发表评论。如果你没有登录,请点击登录
    Csdn Blog version 3.1a
    Copyright © ZPT