“未找到接口”在 WCF Moniker 中,无需注册 excel

发布于 2024-09-04 06:54:13 字数 3077 浏览 2 评论 0原文

我正在尝试将 Excel 连接到 WCF 服务,但我似乎无法让一个简单的案例工作...当我尝试在 Excel 中创建代理时,出现无效语法错误。我已将 Visual Studio 调试器附加到 Excel,并发现真正的错误是“找不到接口”。我知道该服务有效,因为 Visual Studio 创建的测试客户端没问题...所以问题出在 VBA 名称字符串中。

我希望找到以下两件事之一:

1)对我的名字字符串进行更正,使这项工作正常进行,或者

2)要下载一个现有的示例项目,其中包含可以正常工作的主机和客户端的源代码。

这是我的 VBA 客户端的代码:

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>

编辑:

对我有用的更新后的名字如下

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/"""

I'm trying to connect excel to a WCF service, but I can't seem to get even a trivial case to work... I get an Invalid Syntax error when I try and create the proxy in excel. I've attached the visual studio debugger to excel, and get that the real error is "interface not found". I know the service works because the test client created by visual studio is ok... so the problem is in the VBA moniker string.

I'm hoping to find one of two things:

1) a correction to my moniker string that will make this work, or

2) an existing sample project to download that has the source for both the host and client that does work.

Here is the code for my VBA client:

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)

I have the following service:

[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);
    }
}

It has the following config file:

<?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>

Edit:

The updated moniker that worked for me was as follows

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/"""

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

毁我热情 2024-09-11 06:54:13

我将创建一个客户端作为 .NET 对象,将其注册为 COM 对象并通过 COM

UPDATE 从 VBA 访问它:
我找到这篇文章:http://msdn.microsoft.com/en-us /library/ms752245.aspx

似乎要使用名字对象,您必须生成一个客户端,然后使用 COM 注册它,然后使用它的 GUID 作为您的类型,而不是您拥有的类型

I would create a client as a .NET object, register it as a COM object and access it from VBA via COM

UPDATE:
I found this article:http://msdn.microsoft.com/en-us/library/ms752245.aspx

It seems that to use the moniker you have to generate a client, and then register it with COM, and then use its GUID as your type, not the type as you have it

小兔几 2024-09-11 06:54:13

我能够通过在名字字符串上的一些关键位置添加一些引号来解决这个问题...不幸的是,将调试器附加到 Excel 不会给您提供有用的反馈,因此修复它是一个猜测和检查的练习。在 VBA 中,名称中的每个字符串都需要用双引号 ("") 括起来。此外,mex 地址中的术语“mex”必须大写,即使我在合同中指定地址为小写。去算算吧。

I was able to fix this by adding some quotes to some key locations on the moniker string... unfortunately, attaching the debugger to Excel gives you less than useful feedback, so fixing it is an exercise in guess and check. In VBA, you need a double quote ("") around each string in the moniker. Additionally, the term "mex" in the mex address must be capitalized, even though I specified the address in the contract as lower case. Go figure.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文