微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

vb6.0 访问webservices

Option Explicit
Private Const Method = "helloworld"
Private Const SoapAction = _
"http://127.0.0.1/helloworld/HelloWorld"
Private Const END_POINT_URL = _
"http://127.0.0.1/helloworld/Service.asmx?WSDL"
Private Const CALC_NS = "http://127.0.0.1/helloworld/"
Private Function Execute() As String
    
    Dim Serializer As SoapSerializer30
    Dim Reader As SoapReader30
    Dim ResultElm As IXMLDOMElement
    Dim FaultElm As IXMLDOMElement
    Dim Connector As SoapConnector30
    
    Set Connector = New HttpConnector30
    On Error GoTo ErrHandle
    Connector.Property("EndPointURL") = END_POINT_URL
    Connector.Connect
    
    ' binding/operation/soapoperation
    Connector.Property("SoapAction") = SoapAction
    Connector.BeginMessage
    
    Set Serializer = New SoapSerializer30
    Serializer.Init Connector.InputStream
    
    'Serializer.StartEnvelope "SOAP","http://schemas.xmlsoap.org/soap/envelope/",""
    'Serializer.soapAttribute "xsi","","http://www.w3.org/2001/XMLSchema-instance","xmlns"
    'Serializer.soapAttribute "xsd","http://www.w3.org/2001/XMLSchema","xmlns"
    
    Serializer.StartEnvelope
    Serializer.StartBody
    Serializer.StartElement Method,CALC_NS
    Serializer.EndElement
    Serializer.EndBody
    Serializer.EndEnvelope
    
    Connector.EndMessage
        
    Set Reader = New SoapReader30
    Reader.Load Connector.OutputStream
    
    If Not Reader.Fault Is nothing Then
        MsgBox Reader.FaultString.Text,vbExclamation
    Else
        Execute = Reader.RpcResult.xml
    End If
    Exit Function
ErrHandle:
    MsgBox Err.Description,vbExclamation,"错误"

End Function

Private Sub Command1_Click()
MsgBox Execute()
End Sub


原文地址:https://www.jb51.cc/vb/256904.html

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐