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

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

相关文章

Format[$] ( expr [ , fmt ] ) format 返回变体型 format$ 强制返回为文本 --------------------------...
VB6或者ASP 格式化时间为 MM/dd/yyyy 格式,竟然没有好的办法, Format 或者FormatDateTime 竟然结果和...
在项目中添加如下代码:新建窗口来显示异常信息。 Namespace My ‘全局错误处理,新的解决方案直接...
转了这一篇文章,原来一直想用C#做k3的插件开发,vb没有C#用的爽呀,这篇文章写与2011年,看来我以前没...
Sub 分列() ‘以空格为分隔符,连续空格只算1个。对所选中的单元格进行处理 Dim m As Range, t...
  窗体代码 1 Private Sub Text1_OLEDragDrop(Data As DataObject, Effect As Long, Button As Integ...