最新动态
在VB6或ASP中调用webservice-.NET教程,Web Service开发
2024-12-03 19:51

vb6或asp中调用webservice

web services技术使异种计算环境之间可以共享数据和通信,达到信息的一致性。我们可以利用

http post/get协议、soap协议来调用web services。

一、 利用soap协议在vb6中调用web services

; 首先利用.net发布一个简单的web services

<webmethod()> _

public function getstring(byval str as string) as string

return "hello world, " & str & "!"

end function

该web services只包含一个getstring方法,用于返回一个字符串。当我们调用这个web services时,发送给.asmx页面的soap消息为:

<?xml version="1.0" encoding="utf-8"?>

<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/">

<soap:body>

<getstring xmlns="http://tempuri.org/testwebservice/service1">

<str>string</str>

</getstring>

</soap:body>

</soap:envelope>

而返回的soap消息为:

<?xml version="1.0" encoding="utf-8"?>

<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/">

<soap:body>

<getstringresponse xmlns="http://tempuri.org/testwebservice/service1">

<getstringresult>string</getstringresult>

</getstringresponse>

</soap:body>

</soap:envelope>

; 在vb6中调用这个简单的web services可以利用利用xmlhttp协议向.asmx页面发

送soap来实现。

在vb6中,建立一个简单的工程,界面如图,我们通过点击button来调用这个简

在VB6或ASP中调用webservice-.NET教程,Web Service开发

单的web services

dim strxml as string

dim str as string

str = text2.text

定义soap消息

strxml = "<?xml version=1.0 encoding=utf-8?><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/><soap:body><getstring xmlns=http://tempuri.org/testwebservice/service1><str>" & str &

"</str></getstring></soap:body></soap:envelope>"

定义一个http对象,一边向服务器发送post消息

dim h as msxml2.serverxmlhttp40

定义一个xml的文档对象,将手写的或者接受的xml内容转换成xml对象

dim x as msxml2.domdocument40

初始化xml对象

set x = new msxml2.domdocument40

将手写的soap字符串转换为xml对象

x.loadxml strxml

初始化http对象

set h = new msxml2.serverxmlhttp40

向指定的url发送post消息

h.open "post", "http://localhost/testwebservice/service1.asmx", false

h.setrequestheader "content-type", "text/xml"

h.send (strxml)

while h.readystate <> 4

wend

显示返回的xml信息

text1.text = h.responsetext

将返回的xml信息解析并且显示返回值

set x = new msxml2.domdocument40

x.loadxml text1.text

text1.text = x.childnodes(1).text

    以上就是本篇文章【在VB6或ASP中调用webservice-.NET教程,Web Service开发】的全部内容了,欢迎阅览 ! 文章地址:http://ww.kub2b.com/news/2298.html
     栏目首页      相关文章      动态      同类文章      热门文章      网站地图      返回首页 企库往资讯移动站 http://ww.kub2b.com/mobile/ , 查看更多   
最新文章
核心城市土地市场升温 地块成交楼面价频创新高
  随着楼市逐步显现企稳迹象,土地市场也持续升温。3月份,北京、杭州、成都等核心一线、二线城市均有地块成交楼面价创出新高
欧洲将为乌克兰提供价值两百万枚炮弹的资金
据乌克兰国家通讯社报道,乌克兰总理什米哈尔在电视上称,在布鲁塞尔举行的欧盟-乌克兰联盟理事会会谈期间,讨论了为乌克兰国防
咸宁佳能发布EOS R5 Mark II,摄影爱好者迎...工业手机「咸宁佳能发布EOS R5 Mark II,摄影爱好者迎...」
烟台惠诚佳业电子科技有限公司成立于2017年,公司从计算机软、硬件营销,发展成为现今以投影机、数码相机、摄像机营销,多媒体投
拳皇VS街霸街头霸王下载手机版「拳皇VS街霸」
拳皇VS街霸是一款动作格斗游戏,在游戏中玩家会体验到丰富的皇斗玩法,一切都值得玩家去体验,成为一名格斗高手,不断地进行在手
陪嫁火缸是啥?杭州有饭店收藏这份“时光密码”,炭火煨出娘家味道
潮新闻客户端 记者 孙韵在浙江部分地区,上世纪80年代还有陪嫁火缸。它们看着像水缸,但其实里面烧炭,上面可以用砂锅或者瓦罐煨
朝鲜有5条奇葩规矩,千万不能碰!一不小心有可能“小命不保”朝鲜手机「朝鲜有5条奇葩规矩,千万不能碰!一不小心有可能“小命不保”」
朝鲜是全世界最神秘的国家之一,也是我们的邻居,许多游客都想去朝鲜旅游,看一看这个神秘的国度。不过,去之前一定要了解当地这
小米手机怎么投屏电视小米手机怎么投屏到电视「小米手机怎么投屏电视」
使用小米手机投屏电视的步骤:确保手机和电视连接到同一 Wi-Fi 网络。在小米手机上开启投屏功能(从屏幕顶部向下滑动,点击“投
小屏旗舰复兴:除了OVM,华为、荣耀也要加入战局!小屏旗舰手机「小屏旗舰复兴:除了OVM,华为、荣耀也要加入战局!」
回顾过去几年,随着大屏幕、高刷新率和全面屏技术的普及,智能手机屏幕尺寸逐渐膨胀至6.7英寸左右,这也让新机的堆料程度变得很
手机运行内存有什么用手机运行内存是什么意思「手机运行内存有什么用」
在智能手机日益普及的今天,我们经常会听到“运行内存”这个词。对于很多非专业人士来说,可能并不清楚手机运行内存(RAM)到底
手机进水了怎么排水手机进水了「手机进水了怎么排水」
手机进水了是很多人都可能遇到的情况,比如不小心把手机掉进水里,或者在下雨天被淋湿了。手机进水了会影响手机的性能,甚至导致