VB6调用WebService、WCF

'调用webservice。需要安装SoapToolkit30.EXE,并在工程中引用Microsoft Soap Type Library v3.0

Sub CallWebService()

    Dim m_spClient As New SoapClient30 'SoapClient30对象实例化

    m_spClient.MSSoapInit "http://localhost/MCISWebService/vbtest.asmx?WSDL" '引用webservice

    MsgBox m_spClient.HelloWorld '调用webservice方法

End Sub

 

 

'http方式调用WCF

Sub CallHTTPWCFService()

    Dim mexMonikerString As String
    Dim mexServiceMoniker As Object
    '---------------------------------------------------------------
    ' MEX service moniker example
    '---------------------------------------------------------------
    ' Create a string for the service moniker specifying the address
    ' to retrieve the service metadata from
    mexMonikerString = "service:mexAddress='http://localhost:55242/Service1.svc/mex'"
    mexMonikerString = mexMonikerString + ", address='http://localhost:55242/Service1.svc'"
    mexMonikerString = mexMonikerString + ", binding=WSHttpBinding_IService1, bindingNamespace='http://tempuri.org/'"
    mexMonikerString = mexMonikerString + ", contract=IService1, contractNamespace='http://tempuri.org/'"
    ' Create the service moniker object
    Set mexServiceMoniker = GetObject(mexMonikerString)
    
    ' Call the service operations using the moniker object
    MsgBox mexServiceMoniker.SayHello("China!")

    Set mexServiceMoniker = Nothing

End Sub

 

'TCP方式调用WCF

 Sub CallTCPWCFService()

    Dim mexMonikerString As String

    Dim mexServiceMoniker As Object

    ' Create a string for the service moniker specifying the address

    ' to retrieve the service metadata from

    mexMonikerString = "service:mexAddress='http://192.168.1.110:12345/Binding/mex'"

    mexMonikerString = mexMonikerString + ", address='net.tcp://192.168.1.110:54321/Binding/Hello'"

    mexMonikerString = mexMonikerString + ", binding='NetTcpBinding_IHello', bindingNamespace='http://tempuri.org/'"

    mexMonikerString = mexMonikerString + ", contract=IHello, contractNamespace='http://tempuri.org/'"    

    ' Create the service moniker object

    Set mexServiceMoniker = GetObject(mexMonikerString)

    ' Call the service operations using the moniker object

    MsgBox mexServiceMoniker.SayHello("China!")

    Set mexServiceMoniker = Nothing

End Sub

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值