最近的项目中要用到web service,通过internet 发现vb就可以实现soap的客户端,要用到MSSOAPLib.SoapClient,MSSOAPLib.SoapSerializer...
这些东东.
实现代码如下(老外的)
VERSION 5.00
Begin VB.Form Form1
Caption = "Form1"
ClientHeight = 2475
ClientLeft = 60
ClientTop = 345
ClientWidth = 4575
LinkTopic = "Form1"
ScaleHeight = 2475
ScaleWidth = 4575
StartUpPosition = 3 'Windows Default
Begin VB.CommandButton Command1
Caption = "Command1"
Height = 615
Left = 960
TabIndex = 0
Top = 720
Width = 2295
End
End
Attribute VB_Name = "Form1"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Public sClient As New MSSOAPLib.SoapClient
Private Const c_WSDL_URL As String = _
" http://cst48/espresentation/webservices/systemstatus.asmx?WSDL "
'You need soap Type library 3.0 and microsoft xml v2.6to run this example
Private Sub Command1_Click()
'sClient.mssoapinit c_WSL_URL
Debug.Print Time
TranslateBabel
Debug.Print Time
MsgBox "finish "
End Sub
Public Sub TranslateBabel()
' Purpose: Translates text from one language to another.
' WSDL: http://services.xmltoday.com/vx_engine/wsdl_publish.vep/translate.wsdl
' More info: http://www.xmethods.net/detail.html?id=94 http://www.56city.net
Dim objClient As MSSOAPLib.SoapClient
' To package SOAP request.
Dim objSerial As MSSOAPLib.SoapSerializer
' To read SOAP response.
Dim objRead As MSSOAPLib.SoapReader
' To connect to Web service using SOAP.
Dim objConn As MSSOAPLib.SoapConnector
' To parse the SOAP response.
Dim objResults As MSXML2.IXMLDOMNodeList
Dim objNode As MSXML2.IXMLDOMNode
' Set up the SOAP connector.
Set objConn = New MSSOAPLib.HttpConnector
' Define the endpoint URL. This is the actual running code,
' not the WSDL file path! You can find it in the WSDL's
'
1<soap:address> tag's location attribute.
2objConn.Property("EndPointURL") = " http://cst48/espresentation/webservices/systemstatus.asmx "
3' Define the SOAP action. You can find it in the WSDL's
4' <soap:operation> tag's soapAction attribute for the matching
5' <operation> tag.
6
7'GetNaturalInfo is the name of the service
8objConn.Property("SoapAction") = " http://tempuri.org/GetNaturalInfo "
9'objConn.Property("SoapAction") = "GetNaturalInfo"
10
11' Begin the SOAP message.
12objConn.BeginMessage
13
14Set objSerial = New MSSOAPLib.SoapSerializer
15' Initialize the serializer to the connector's input stream.
16objSerial.Init objConn.InputStream
17
18' Build the SOAP message.
19With objSerial
20.startEnvelope ' <soap-env:envelope>
21.startBody ' <soap-env:body>
22' Use the Web method's name and schema target namespace URI.
23.startElement "GetNaturalInfo"
24.endElement
25.endBody ' </soap-env:body>
26.endEnvelope ' </soap-env:envelope>
27End With
28
29' Send the SOAP message.
30objConn.EndMessage
31
32Set objRead = New MSSOAPLib.SoapReader
33
34' Initialize the SOAP reader to the connector's output stream.
35objRead.Load objConn.OutputStream
36
37Set objResults = objRead.RPCResult.childNodes
38
39' Iterate through the returned nodes.
40For Each objNode In objResults
41'Debug.Print objNode.nodeValue
42MsgBox objNode.nodeTypedValue
43Next objNode
44
45
46End Sub</operation></soap:operation></soap:address>