wcf - 通过 Excel VBA 从 WCF 服务调用方法

标签 wcf excel vba

我已经通过 WCF Web 服务创建了一个方法。我已将其上传到我的服务器。我想做的是在 Excel VBA 宏中调用该方法。可能吗?

类似于:

Dim client As DaybookServicesClient = New DaybookServicesClient()
' Use the 'client' variable to call operations on the service.

' Calls my method
client.ExecuteSQLJob()

' Always close the client.
client.Close()

如何在 Excel VBA 中引用我的服务?

最佳答案

一种方法可以创建 WebGet wcf 服务,该服务将返回 adorecordset xml,在宏上您可以使用以下代码获取记录集

    Public Function GetRSFromString(sXML As String) As Object
   Dim oStream As Object, oRecordset As Object
   Set oStream = CreateObject("ADODB.Stream")
   oStream.Open
   oStream.WriteText sXML
   oStream.Position = 0
   Set oRecordset = CreateObject("ADODB.Recordset")
   oRecordset.Open oStream
   oStream.Close
   Set oStream = Nothing
   Set GetRSFromString = oRecordset
   Set oRecordset = Nothing
End Function


Public Function GetSoapRequest()
    Dim strResult As String
    Dim xmlhtp As Object, xmlDoc As Object, oRecordSetFromXML As Object
    Set xmlhtp = CreateObject("msxml2.xmlhttp.6.0")
    With xmlhtp
            .Open "get", "http://[server]/ServiceName.svc/FunctionName", False
            .setRequestHeader "Content-Type", "application/x-www-form-urlencoded"
            .Send
            Set xmlDoc = CreateObject("msxml2.DOMDocument.6.0")
            strResult = .responseText
            xmlDoc.loadXML strResult
            Set oRecordSetFromXML = AdoFunction .GetRSFromString(xmlDoc.Text)
    End With
    Set xmlDoc = Nothing
    Set xmlhtp = Nothing               
End Function

关于wcf - 通过 Excel VBA 从 WCF 服务调用方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11154896/

相关文章:

c# - 如何在使用数据库的 WCF 服务中处理并发

java - 从xls/xlsx文档中读取,哪个API? java

vba - Excel VBA : Remove ListBox Item if in Array

excel - 如何获取打开的工作簿的文件扩展名

c# - WCF 和 Ajax。不允许的方法让我发疯

c# - 使用测试数据库集成测试链式 WCF 服务

vba - 从文件夹中的所有工作簿中删除 VBA 代码

excel - 当文本长度溢出用户表单文本框时触发事件

excel - 如何使用appIE.Document.Body.innerHTML

wcf - 保护游戏高分的解决方案