加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > 安全 > 正文

在脚本语言中调用WebService的方法

发布时间:2020-12-17 02:32:23 所属栏目:安全 来源:网络整理
导读:?1. 在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;

?1. 在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 + "&#124;" + 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中调用WebService<%@LANGUAGE="VBSCRIPT" CODEPAGE="936"%><%Dim strxmlDim 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",Falseh.setRequestHeader "Content-Type","text/xml"h.setRequestHeader "SOAPAction","http://tempuri.org/myService/test/isNumner"h.send (strxml)While h.readyState <> 4Wend'显示返回的XML信息str = h.responseText'将返回的XML信息解析并且显示返回值Set x = createobject("MSXML2.DOMDocument")x.loadXML strstr = x.childNodes(1).Textresponse.write(str)%>3.在.net中调用WebService  在.net中调用WebService就方便多了,没有必要自己写soap消息了,以上都是用XMLHTTP来发送WebService请求的,在.net只要添加了web引用,会自动为你创建一个代理类。然后使用代理类就像用自己定义的类一样方便。4、如何在ASP中调用由Delphi编写的WebServiceQ:那么又如何在ASP中调用由Delphi编写的WebService呢?A:上微软网站下个Microsoft SOAP Toolkit 3.0安装,就可以在asp里调用webservice了,调用方法如下:Microsoft SOAP Toolkit(MSST)可以到微软网站免费下载:http://download.microsoft.com/download/xml/Install/3.0/W982KMeXP/EN-US/SoapToolkit30.EXE??<%????'Calling?? a?? Web?? service?? using?? Microsoft?? SOAP?? Toolkit?? 3.0???????OPTION?? EXPLICIT???????Dim?? strWebSvcWSDLURL????Dim?? objSOAPClient???????strWebSvcWSDLURL?? ="http://localhost/jfgl/jfglWebSrv.dll/wsdl/IjfglWebSrv"?????Set?? objSOAPClient?? =?? Server.CreateObject("MSSOAP.SoapClient30")????objSOAPClient.ClientProperty("ServerHTTPRequest")?? =?? True???????objSOAPClient.MSSoapInit?? strWebSvcWSDLURL,?? "",?? ""???????dim?? s????s?? =?? objSOAPClient.Get_Sql_Time?? //调用soap里的方法????response.write?? s????%>

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读