推广 热搜: page  音视频  使用  搜索引擎  选择  个数  企业  百度  可以  父亲 

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

   日期:2024-12-03     来源:本站    作者:ujtaa    caijiyuan   评论:0    移动:http://ww.kub2b.com/mobile/news/2298.html
核心提示:vb6或asp中调用webserviceweb services技术使异种计算环境之间可以共享数据和通信,达到信息的一致性。我们可以利用http post/ge

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

本文地址:http://ww.kub2b.com/news/2298.html     企库往 http://ww.kub2b.com/ ,  查看更多

特别提示:本信息由相关用户自行提供,真实性未证实,仅供参考。请谨慎采用,风险自负。

 
 
更多>同类最新文章
0相关评论

文章列表
相关文章
最新动态
推荐图文
最新文章
点击排行
网站首页  |  关于我们  |  联系方式  |  使用协议  |  版权隐私  |  网站地图  |  排名推广  |  广告服务  |  积分换礼  |  网站留言  |  RSS订阅  |  违规举报  |  鄂ICP备2020018471号