Я пытаюсь подключить Excel к службе WCF, но не могу заставить работать даже тривиальный случай ... Я получаю ошибку Invalid Syntax при попытке создать прокси в 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>
Edit:
Обновленный моникер, который работал для меня, был следующим
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/"""