惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

H
Help Net Security
博客园 - Franky
GbyAI
GbyAI
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
爱范儿
爱范儿
IT之家
IT之家
酷 壳 – CoolShell
酷 壳 – CoolShell
aimingoo的专栏
aimingoo的专栏
博客园_首页
MongoDB | Blog
MongoDB | Blog
CTFtime.org: upcoming CTF events
CTFtime.org: upcoming CTF events
Recent Announcements
Recent Announcements
Scott Helme
Scott Helme
有赞技术团队
有赞技术团队
M
MIT News - Artificial intelligence
C
CERT Recently Published Vulnerability Notes
K
KPMG report finds enterprise disconnect between AI and its ROI | CIO
Jina AI
Jina AI
F
Fortinet All Blogs
N
Netflix TechBlog - Medium
L
LangChain Blog
L
LINUX DO - 最新话题
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
H
Hacker News: Front Page
MyScale Blog
MyScale Blog
P
Palo Alto Networks Blog
G
Google Developers Blog
Google DeepMind News
Google DeepMind News
AI
AI
T
Troy Hunt's Blog
Microsoft Azure Blog
Microsoft Azure Blog
阮一峰的网络日志
阮一峰的网络日志
cs.CL updates on arXiv.org
cs.CL updates on arXiv.org
Vercel News
Vercel News
Microsoft Security Blog
Microsoft Security Blog
罗磊的独立博客
S
Secure Thoughts
大猫的无限游戏
大猫的无限游戏
博客园 - 叶小钗
人人都是产品经理
人人都是产品经理
Blog — PlanetScale
Blog — PlanetScale
博客园 - 司徒正美
Apple Machine Learning Research
Apple Machine Learning Research
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
博客园 - 三生石上(FineUI控件)
S
Security @ Cisco Blogs
Cloudbric
Cloudbric
E
Exploit-DB.com RSS Feed
Attack and Defense Labs
Attack and Defense Labs

博客园 - 慕晓

10.23 关注 可中期关注的股票 关于利润率的趋同 为什么要学ruby? 到底用哪个blog好。 富人更富,穷人更穷 请问有没有c#.net的讲师或者类似的人或公司? 微软拼音输入法3.0 在 ie 中有MaxLength 的 textbox 框中输入的bug 把Linux 的线程操作封装在类里面 发现word的一个bug :项目符号和编号 中 多级符号 如何更改级别? 提问:使用何种模式? 重新构造我现有软件的结构(一) 发现了个叫做saie.exe的spyware程序 关于默认按钮 数据库连接的位置 我画的数据库的关系 简单介绍 求助:asp.net无法调试,为什么? 自己写的vss使用文档,入门级别的,大家随便看看
在 javascript中调用WebService(转) - 慕晓 - 博客园
慕晓 · 2006-12-04 · via 博客园 - 慕晓

在JavaScript中调用WebService 的几种方法

第一种方法
<script language="javascript">
function PostRequestData(URL,data){ 
   var xmlhttp = new ActiveXObject("Microsoft.XMLHTTP"); 
   xmlhttp.Open("POST",URL, false); 
   xmlhttp.SetRequestHeader ("Content-Type","text/xml; charset=utf-8"); 
   xmlhttp.SetRequestHeader ("SOAPAction","http://tempuri.org/myService/test/isNumner"); 
   try { 
      xmlhttp.Send(data); 
      var result = xmlhttp.status; 
   } 
   catch(ex) { 
      return("0" + ex.description + "|" + ex.number); 
   } 
   
   if(result==200) { 
      return("1" + xmlhttp.responseText); 
   } 
   xmlhttp = null;

}

第二种方法
function loadit(value){ 
   var url = 'http://localhost/myService/test.asmx'; 
   var data ; 
   var r; 

   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 + '<isNumner xmlns="http://tempuri.org/myService/test">'; 
   data = data + '<str>'+value+'</str>'; 
   data = data + '</isNumner>'; 
   data = data + '</soap:Body>'; 
   data = data + '</soap:Envelope>'; 

   r=PostRequestData(url,data); 
   document.write(r);

}

loadit('5');
</script>

第三种方法: 使用微软的htc组件来实现,可以到这里下载:

http://msdn.microsoft.com/workshop/author/webservice/webservice.htc

<script language="javascript">
function timer(){ 
   service.useService("http://localhost/myService/test.asmx?WSDL","test"); 
   service.test.callService(callback,"isNumner",'gdh');

}

function callback(res){ 
   if (!res.error) 
   time.innerText=res.value;
}

</script>

<div id="service" style="behavior:url(webservice.htc)"></div>
<span id="time"></span>

2. 在Asp中

<%@LANGUAGE="VBSCRIPT" CODEPAGE="936"%>

<% 
   Dim strxml 
   Dim str 
   
'定义soap消息 

   strxml = "<?xml version='1.0' encoding='tf-8'?>" 
   strxml = strxml & "<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/'>" 
   strxml = strxml & "<soap:Body> " 
   strxml = strxml & "<isNumner xmlns='http://tempuri.org/myService/test'>" 
   strxml = strxml & "<str>4</str>" 
   strxml = strxml & "</isNumner>" 
   strxml = strxml & "</soap:Body>" 
   strxml = strxml & "</soap:Envelope>"

'定义一个XML的文档对象,将手写的或者接受的XML内容转换成XML对象 
   'set x = createobject("Microsoft.DOMDocument") 
   '初始化XML对象 
   '将手写的SOAP字符串转换为XML对象 
   ' x.loadXML strxml 
   '初始化http对象 
   Set h = createobject( "Microsoft.XMLHTTP") 
   '向指定的URL发送Post消息 
   h.open "POST", "http://localhost/myService/test.asmx", False 
   h.setRequestHeader "Content-Type", "text/xml" 
   h.setRequestHeader "SOAPAction", "http://tempuri.org/myService/test/isNumner" 
   h.send (strxml) 
   While h.readyState <> 4 
   Wend 
   '显示返回的XML信息 
   str = h.responseText

'将返回的XML信息解析并且显示返回值 
   'Set x = createobject("MSXML2.DOMDocument") 
   ' x.loadXML str 
   'str = x.childNodes(1).Text 
   response.write(str)

%>

3.在.net中

在.net中调用WebService就方便多了,没有必要自己写soap消息了,以上都是用XMLHTTP来发送WebService请求的,在.net只要添加了web引用,会自动为你创建一个代理类。然后使用代理类就像用自己定义的类一样方便。