如何从Excel 2003 VBA调用WCF客户端?

时间:2022-10-30 23:19:01

As the question asked, how do I call WCF client from Excel 2003 VBA?

如问题所问,如何从excel2003 VBA调用WCF客户端?

I saw there is a place where I can call web service, but I have searched through Google, all the results I get is not possible to call a WCF client from VBA.

我看到有一个地方可以调用web服务,但是我已经通过谷歌进行了搜索,我得到的所有结果都无法从VBA调用WCF客户机。

I would like to know sort of what method to use before I do anything with my code, don't want to waste the time and discover later that it is not possible to do that.

我想知道在我对代码做任何事情之前应该使用什么方法,不要浪费时间,以后发现不可能那样做。

4 个解决方案

#1


12  

You might want to look at using the WCF Service Moniker which lets you invoke a WCF Service from VBA without installing anything on the Excel client machine other than the .NET Framework.

您可能希望使用WCF服务名称,它允许您从VBA调用WCF服务,而无需在. net框架之外的Excel客户机机器上安装任何东西。

Dim addr As String
addr = "service:mexAddress=""net.tcp://localhost:7891/Test/WcfService1/Service1/Mex"","
addr = addr + "address=""net.tcp://localhost:7891/Test/WcfService1/Service1/"","
addr = addr + "contract=""IService1"", contractNamespace=""http://tempuri.org/"","
addr = addr + "binding=""NetTcpBinding_IService1"",bindingNamespace=""http://tempuri.org/"""

Dim service1 As Object
Set service1 = GetObject(addr)

MsgBox service1.GetData(12)

I've written out a complete step-by-step example.

我已经写出了一个完整的一步一步的例子。

/Damian

/ Damian

#2


2  

I tried for quite a while to call a SOAP based wcf service from excel vba without any luck.

Instead I changed my service to REST binding (webHttpBinding). That way I could load the data stright into an xml map like it was any other xml file. Worked well for me, but I was only trying to import some data.

As for SOAP; an answer in this question mentions the Web Services Toolkit all the examples I could find suggested to use.

我花了很长时间从excel vba调用基于SOAP的wcf服务。相反,我将服务更改为REST绑定(webHttpBinding)。这样,我就可以像加载其他xml文件一样将数据stright加载到xml映射中。我工作得很好,但我只是想导入一些数据。至于肥皂;这个问题的一个答案提到了Web服务工具包,我找到的所有示例都建议使用它。

#3


2  

I wouldn't use VSTO in this case. COM Interop is probably the best way to go, so long as you don't want any security in your SOAP messages.

我不会在这种情况下使用VSTO。COM Interop可能是最好的方法,只要您不希望SOAP消息中有任何安全性。

  1. Write WCF client, with necessary binding
  2. 编写WCF客户端,具有必要的绑定。
  3. Expose assembly for COM Interop
  4. 公开COM对讲程序集
  5. Reference exposed assembly in Excel VBA
  6. 在Excel VBA中引用公开的程序集

#4


1  

I have done this with limited success using the Office 2003 Web Services Toolkit, but not without some pain.

我在使用Office 2003 Web服务工具包时取得了有限的成功,但也有一些痛苦。

Note that this is not supported by Microsoft, and has a number of restrictions which may make it unsuitable for production use. E.g. it does not support web services that return an empty collections : see this * question.

请注意,这不是微软支持的,并且有一些限制,可能使它不适合生产使用。例如,它不支持返回空集合的web服务:请参阅*问题。

If you want to go this route despite it being unsupported, download the toolkit and post any problems you're having here.

如果您想在不受支持的情况下使用此方法,请下载工具箱并在这里发布任何问题。

Microsoft recommends using VSTO, but this doesn't integrate easily with VBA...

微软建议使用VSTO,但是这并不能很容易地与VBA集成…

#1


12  

You might want to look at using the WCF Service Moniker which lets you invoke a WCF Service from VBA without installing anything on the Excel client machine other than the .NET Framework.

您可能希望使用WCF服务名称,它允许您从VBA调用WCF服务,而无需在. net框架之外的Excel客户机机器上安装任何东西。

Dim addr As String
addr = "service:mexAddress=""net.tcp://localhost:7891/Test/WcfService1/Service1/Mex"","
addr = addr + "address=""net.tcp://localhost:7891/Test/WcfService1/Service1/"","
addr = addr + "contract=""IService1"", contractNamespace=""http://tempuri.org/"","
addr = addr + "binding=""NetTcpBinding_IService1"",bindingNamespace=""http://tempuri.org/"""

Dim service1 As Object
Set service1 = GetObject(addr)

MsgBox service1.GetData(12)

I've written out a complete step-by-step example.

我已经写出了一个完整的一步一步的例子。

/Damian

/ Damian

#2


2  

I tried for quite a while to call a SOAP based wcf service from excel vba without any luck.

Instead I changed my service to REST binding (webHttpBinding). That way I could load the data stright into an xml map like it was any other xml file. Worked well for me, but I was only trying to import some data.

As for SOAP; an answer in this question mentions the Web Services Toolkit all the examples I could find suggested to use.

我花了很长时间从excel vba调用基于SOAP的wcf服务。相反,我将服务更改为REST绑定(webHttpBinding)。这样,我就可以像加载其他xml文件一样将数据stright加载到xml映射中。我工作得很好,但我只是想导入一些数据。至于肥皂;这个问题的一个答案提到了Web服务工具包,我找到的所有示例都建议使用它。

#3


2  

I wouldn't use VSTO in this case. COM Interop is probably the best way to go, so long as you don't want any security in your SOAP messages.

我不会在这种情况下使用VSTO。COM Interop可能是最好的方法,只要您不希望SOAP消息中有任何安全性。

  1. Write WCF client, with necessary binding
  2. 编写WCF客户端,具有必要的绑定。
  3. Expose assembly for COM Interop
  4. 公开COM对讲程序集
  5. Reference exposed assembly in Excel VBA
  6. 在Excel VBA中引用公开的程序集

#4


1  

I have done this with limited success using the Office 2003 Web Services Toolkit, but not without some pain.

我在使用Office 2003 Web服务工具包时取得了有限的成功,但也有一些痛苦。

Note that this is not supported by Microsoft, and has a number of restrictions which may make it unsuitable for production use. E.g. it does not support web services that return an empty collections : see this * question.

请注意,这不是微软支持的,并且有一些限制,可能使它不适合生产使用。例如,它不支持返回空集合的web服务:请参阅*问题。

If you want to go this route despite it being unsupported, download the toolkit and post any problems you're having here.

如果您想在不受支持的情况下使用此方法,请下载工具箱并在这里发布任何问题。

Microsoft recommends using VSTO, but this doesn't integrate easily with VBA...

微软建议使用VSTO,但是这并不能很容易地与VBA集成…