VB6调用WebService、WCF

前端之家收集整理的这篇文章主要介绍了VB6调用WebService、WCF前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

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

Sub CallWebService()

Dimm_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()

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

猜你在找的VB相关文章