&引用;“未找到接口”;在未注册excel的WCF名字对象中
我正在尝试将excel连接到WCF服务,但我似乎连一个小案例都无法正常工作。。。尝试在excel中创建代理时,出现无效语法错误。我已将VisualStudio调试器附加到excel,并发现真正的错误是“找不到接口”。我知道这项服务是有效的,因为VisualStudio创建的测试客户端是正常的。。。所以问题出在VBA名字对象字符串中 我希望找到两件事中的一件: 1) 对我的名字对象字符串的更正将使此工作正常,或 2) 要下载的现有示例项目,该项目的源代码同时适用于运行的主机和客户端 以下是我的VBA客户端的代码:&引用;“未找到接口”;在未注册excel的WCF名字对象中,wcf,excel,moniker,mex-bindings,Wcf,Excel,Moniker,Mex Bindings,我正在尝试将excel连接到WCF服务,但我似乎连一个小案例都无法正常工作。。。尝试在excel中创建代理时,出现无效语法错误。我已将VisualStudio调试器附加到excel,并发现真正的错误是“找不到接口”。我知道这项服务是有效的,因为VisualStudio创建的测试客户端是正常的。。。所以问题出在VBA名字对象字符串中 我希望找到两件事中的一件: 1) 对我的名字对象字符串的更正将使此工作正常,或 2) 要下载的现有示例项目,该项目的源代码同时适用于运行的主机和客户端 以下是我的VB
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"""
MsgBox (addr)
Dim service1 As Object
Set service1 = GetObject(addr)
MsgBox service1.Test(12)
我有以下服务:
[ServiceContract]
public interface IService1
{
[OperationContract]
string GetData(int value);
}
public class Service1 : IService1
{
public string GetData(int value)
{
return string.Format("You entered: {0}", value);
}
}
它具有以下配置文件:
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<system.web>
<compilation debug="true" />
</system.web>
<!-- When deploying the service library project, the content of the config file must be added to the host's
app.config file. System.Configuration does not support config files for libraries. -->
<system.serviceModel>
<services>
<service behaviorConfiguration="WcfService1.Service1Behavior"
name="WcfService1.Service1">
<endpoint address="" binding="netTcpBinding" bindingConfiguration=""
contract="WcfService1.IService1">
<identity>
<dns value="localhost" />
</identity>
</endpoint>
<endpoint address="mex" binding="mexTcpBinding" bindingConfiguration=""
contract="IMetadataExchange" />
<host>
<baseAddresses>
<add baseAddress="net.tcp://localhost:7891/Test/WcfService1/Service1/" />
</baseAddresses>
</host>
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior name="WcfService1.Service1Behavior">
<serviceMetadata httpGetEnabled="false" />
<serviceDebug includeExceptionDetailInFaults="false" />
</behavior>
</serviceBehaviors>
</behaviors>
</system.serviceModel>
</configuration>
我将创建一个作为.NET对象的客户端,将其注册为COM对象,并通过COM从VBA访问它 更新: 我发现这篇文章:
似乎要使用名字对象,您必须生成一个客户端,然后在COM中注册它,然后使用它的GUID作为您的类型,而不是您的类型我可以通过在名字对象字符串上的一些关键位置添加一些引号来解决这个问题。。。不幸的是,将调试器附加到Excel会给您提供不太有用的反馈,因此修复它是一个猜测和检查的练习。在VBA中,名字对象中的每个字符串周围都需要一个双引号(“”)。此外,mex地址中的“mex”一词必须大写,即使我在合同中指定地址为小写。想想看。虽然这是建立连接的另一种方式,但重点是尝试学习用WCF方式建立连接。。。但是,我正在使用元数据交换契约来获取工作基准。我从你链接的那篇文章开始工作。。。请注意“元数据交换合同”部分。您是否介意更新/编辑您的原始帖子以反映您所做的对您有用的更改?我遇到了相同的问题,并尝试了您更改的内容。当WCF服务将非基本类型的方法作为参数或返回类型公开时,也会发生相同的错误。
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/"""