国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 編程 > ASP > 正文

在VB6或ASP中調用webservice

2024-05-04 11:06:31
字體:
來源:轉載
供稿:網友

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來調用這個簡

單的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



我們在textbox中輸入“中國”,再點擊button,于是就可以在下邊的textbox中顯示“hello world, 中國” 。顯示如圖:

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 万载县| 天台县| 信阳市| 怀远县| 许昌县| 偏关县| 双柏县| 新绛县| 南康市| 泸州市| 白朗县| 岳池县| 乡城县| 株洲市| 遵义市| 赫章县| 台中市| 故城县| 朔州市| 来宾市| 凤冈县| 栖霞市| 江山市| 佳木斯市| 察隅县| 永新县| 错那县| 松江区| 巩义市| 香格里拉县| 印江| 嘉荫县| 米脂县| 安宁市| 武冈市| 济阳县| 勐海县| 若羌县| 许昌县| 乳山市| 镇巴县|