百度空间 | 百度首页 
               
 
查看文章
 
javascript可以调用webservice
2007-09-10 16:55

javascript可以调用webservice   
    
   var    xmlserverhttp=new    activexobject("msxml2.serverxmlhttp");   
   xmlserverhttp.open("post","webserviceurl","user,name","pswd");   
   xmlserverhttp.setrequestheader("content-type",    "application/x-www-form-urlencoded");   
   xmlserverhttp.send("msg");

发表者:godblessyu

客户端:   
   <script>   
   function    call()   
   {   
   var    objhttp=new    activexobject("microsoft.xmlhttp")   
   var    xmldoc=new    activexobject("microsoft.xmldom")   
   var    strwebserviceurl="http://localhost/webservice1/service1.asmx/password"    ;   
   var    strrequest="s=dd"    ;   
   objhttp.open    ("post",strwebserviceurl,false);   
   objhttp.setrequestheader("content-type",      "application/x-www-form-urlencoded")    ;   
   objhttp.send(strrequest)   
     //装载   
   if    (xmldoc.load(objhttp.responsexml))    //成功   
   {   
   var    rootnode    =xmldoc.documentelement   
   alert(rootnode.firstchild.xml);   
   }     
   }   
   </script>   
   <html>   
   <body>   
   <input    type=button    onclick=call()    value="ok">   
   </body>   
   </html>   
   服务器端:   
   using    system;   
   using    system.collections;   
   using    system.componentmodel;   
   using    system.data;   
   using    system.diagnostics;   
   using    system.web;   
   using    system.web.services;   
    
   namespace    webservice1   
   {   
   ///    <summary>   
   ///    service1    的摘要说明。   
   ///    </summary>   
   //[webservice(namespace="http://localhost/webserver/")]     
   public    class    service1    :    system.web.services.webservice   
   {   
   public    service1()   
   {   
   //codegen:    该调用是    asp.net    web    服务设计器所必需的   
   initializecomponent();   
   }   
    
   #region    组件设计器生成的代码   
    
   //web    服务设计器所必需的   
   private    icontainer    components    =    null;   
    
   ///    <summary>   
   ///    设计器支持所需的方法    -    不要使用代码编辑器修改   
   ///    此方法的内容。   
   ///    </summary>   
   private    void    initializecomponent()   
   {   
   }   
    
   ///    <summary>   
   ///    清理所有正在使用的资源。   
   ///    </summary>   
   protected    override    void    dispose(    bool    disposing    )   
   {   
   if(disposing    &&    components    !=    null)   
   {   
   components.dispose();   
   }   
   base.dispose(disposing);   
   }   
    
   #endregion   
    
   //    web    服务示例   
   //    helloworld()    示例服务返回字符串    hello    world   
   //    若要生成,请取消注释下列行,然后保存并生成项目   
   //    若要测试此    web    服务,请按    f5    键   
    
   [webmethod]   
   public    string    helloworld()   
   {   
   return    "hello    world";   
    
   }   
   [webmethod]   
   public    string      password(string    s)   
   {   
   byte    []ss;   
   ss=system.text.encoding    .utf8    .getbytes(s)      ;   
   string    sss=null;   
   foreach    (byte    e    in    ss)   
   {   
   sss+=e.tostring    ();   
   }   
   return    sss;   
    
   }   
   }   
   }   
    


类别:默认分类 | 添加到搜藏 | 浏览() | 评论 (0)
 
最近读者:
 
网友评论:
发表评论:
姓 名:
网址或邮箱: (选填)
内 容:
验证码: 请点击后输入四位验证码,字母不区分大小写
      

     

©2009 Baidu