使用Excel中的Service Moniker调用WCF时收到错误

时间:2010-08-18 12:30:03

标签: c# .net vba wcf

我有一个运行WCF的webservice,它有2个端点(mex和wsHttpBinding)。 Web服务在地址http://localhost:2412/Service1.svc上托管,其联系人名为“WcfService1.IService1”

我想在Excel中从VBA调用此服务。为此,我使用下面的代码:

mexMonikerString = "service:mexAddress='http://localhost:2412/Service1.svc/mex'"
mexMonikerString = mexMonikerString + ", address='http://localhost:2412/Service1.svc'"
mexMonikerString = mexMonikerString + ", binding=WSHttpBinding_IService1"
mexMonikerString = mexMonikerString + ", contract=IService1"

Set service = GetObject(mexMonikerString)

当我尝试执行此代码时,我收到以下Excel错误消息: 运行时错误'-2147221020(800401e4)'

有人知道这个错误的原因是什么以及如何解决它?

3 个答案:

答案 0 :(得分:1)

看看Calling WCF Services from Excel VBA clients using the WCF Service Moniker。它有一个关于调试的部分,它显示了您正在接收的相同错误代码以及如何获取实际错误描述(在这种情况下,“未找到接口”)。

答案 1 :(得分:1)

尝试使用以下格式:)

Dim addr As String
addr = "service:mexAddress=""http://localhost:2412/Service1/mex"","
addr = addr + "address=""http://localhost:2412/Service1.svc/"","
addr = addr + "contract=""IService1"", contractNamespace=""http://tempuri.org/"","
addr = addr + "binding=""WSHttpBinding_IService1"", bindingNamespace=""http://tempuri.org/"""

Set service = GetObject(addr)

答案 2 :(得分:0)

您可以尝试在IIS中发布WCF服务。