我試圖將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/"""
當WCF服務將非基元類型的方法作爲參數或返回類型公開時,也會發生同樣的錯誤。 – ssgonell 2011-11-08 00:29:13