2010-06-03 32 views
0

我試圖將excel連接到WCF服務,但我似乎無法得到一個微不足道的情況下工作......我得到一個無效的語法錯誤當我嘗試在Excel中創建代理時。我已經將visual studio調試器附加到excel中,並且得到真正的錯誤是「未找到接口」。我知道這個服務是可行的,因爲Visual Studio創建的測試客戶端是可以的......所以問題出在VBA moniker字符串中。WCF Moniker中的「interface not found」未註冊爲excel

,我希望能找到一兩件事情:

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

當WCF服務將非基元類型的方法作爲參數或返回類型公開時,也會發生同樣的錯誤。 – ssgonell 2011-11-08 00:29:13

回答

0

我可以通過在名字符串上的一些關鍵位置添加一些引號來解決這個問題......不幸的是,將調試器附加到Excel中給你的反饋不夠有用,所以修復它是一個猜測和檢查的練習。在VBA中,綽號中的每個字符串都需要雙引號(「」)。此外,mex地址中的術語「mex」必須大寫,即使我將合同中的地址指定爲小寫。去搞清楚。

+1

您是否介意更新/編輯您的原始文章以反映您所做的更改對您有用?我遇到同樣的問題,並嘗試過你改變的東西。 – 2010-06-16 23:14:12

+1

更新了我所做的更改。 – tbischel 2010-06-17 01:04:30

0

我將創建一個客戶端作爲一個.NET對象,其註冊爲COM對象,並通過COM從VBA訪問

更新: 我發現這篇文章:http://msdn.microsoft.com/en-us/library/ms752245.aspx

似乎使用的綽號,你必須生成客戶端,然後用COM註冊,然後使用其GUID爲你的類型,而不是類型,你擁有了它

+0

雖然這是另一種建立連接的方式,但重點是試圖學習如何使用WCF的方式......但獲取基線工作 – tbischel 2010-06-03 20:32:46

+0

我正在使用元數據交換合同。我一直在從你已鏈接的文章開始工作......請注意「元數據交換合同」部分。 – tbischel 2010-06-07 18:51:43