“未找到接口"在 WCF Moniker 中,无需注册 excel [英] "interface not found" in WCF Moniker without registration for excel

查看:31
本文介绍了“未找到接口"在 WCF Moniker 中,无需注册 excel的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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) 对我的昵称字符串进行更正以使其起作用,或者

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

2) 要下载的现有示例项目,该项目具有主机和客户端的源代码.

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

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

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)

我有以下服务:

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

<小时>

对我有用的更新的绰号如下

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

推荐答案

我能够通过在名字字符串的一些关键位置添加一些引号来解决这个问题……不幸的是,将调试器附加到 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.

这篇关于“未找到接口"在 WCF Moniker 中,无需注册 excel的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆