Я пытаюсь создать две службы WCF, которые должны иметь доступ друг к другу. Однако я получаю это сообщение об ошибке:
Сервер обнаружил ошибку при обработке запроса. Сообщение об исключении: «Не удалось найти элемент конечной точки по умолчанию, который ссылается на контракт« AddonWCFService.IService1 »в разделе конфигурации клиента ServiceModel. Это может быть связано с тем, что для вашего приложения не найден файл конфигурации, или из-за того, что ни один элемент конечной точки, соответствующий этому контракту, не найден в элементе client. '.
Я вызываю метод Test () из этой службы
namespace CustomersService
{
[ServiceContract]
public interface ICustomers
{
[OperationContract]
[WebGet]
string Test();
}
public class Customers : ICustomers
{
private int m_i = 0;
public int GetCounter()
{
return m_i;
}
public void Test()
{
AddonWCFService.Service1Client foo = new AddonWCFService.Service1Client();
}
}
}
Другой сервис
namespace AddonWCFWebservice
{
[ServiceContract]
public interface IService1
{
[OperationContract]
void Init();
}
public class Service1 : IService1
{
public void Init()
{
}
}
}
Мой webconfig:
<?xml version="1.0"?>
<configuration>
<system.serviceModel>
<services>
<service behaviorConfiguration="MyserviceBehavior" name="CustomersService.Customers">
<endpoint name="ws" address="ws" binding="wsHttpBinding" contract="CustomersService.ICustomers"/>
<endpoint name=""
address=""
binding="webHttpBinding"
contract="CustomersService.ICustomers"
behaviorConfiguration="WebBehavior"/>
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"/>
</service>
<service name="AddonWCFWebservice.Service1" behaviorConfiguration="MyserviceBehavior">
<endpoint address="" binding="wsHttpBinding" contract="AddonWCFWebservice.IService1"/>
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"/>
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior name="MyserviceBehavior">
<serviceMetadata httpGetEnabled="true"/>
<serviceDebug includeExceptionDetailInFaults="true"/>
</behavior>
</serviceBehaviors>
<endpointBehaviors>
<behavior name="WebBehavior">
<webHttp />
</behavior>
</endpointBehaviors>
</behaviors>
</system.serviceModel>
<system.web>
<compilation debug="true"/>
<customErrors mode="Off"/>
</system.web>
</configuration>
Обе службы находятся в одном и том же активном каталоге IIS. Я добавил сервисную ссылку в проекты VS C #, используя веб-URL, т.е. http://www.foobar.baz/Test/Service1.svc и http://www.foobar.baz/Test/Customers.svc
Возможно, это что-то очевидное, но я довольно новичок во всем бизнесе WCF. Спасибо!
Обновление : Решением было добавить раздел клиента в мою веб-конфигурацию. Также я использовал basicHttpBinding вместо wsHttpBinding, потому что моя безопасность будет нарушена в другом месте, потому что это публичная служба. Мне пришлось сопоставить привязку клиента к привязке раздела службы: оба basicHttpBinding
<?xml version="1.0"?>
<configuration>
<system.serviceModel>
<client>
<endpoint
name=""
address="http://demo.mydomain.baz/TestService/Service1.svc"
binding="basicHttpBinding"
contract="AddonWCFService.IService1" />
</client>
<services>
<service behaviorConfiguration="MyserviceBehavior" name="CustomersService.Customers">
<endpoint name="ws" address="ws" binding="wsHttpBinding" contract="CustomersService.ICustomers"/>
<endpoint name=""
address=""
binding="webHttpBinding"
contract="CustomersService.ICustomers"
behaviorConfiguration="WebBehavior"/>
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"/>
</service>
<service name="AddonWCFWebservice.Service1" behaviorConfiguration="MyserviceBehavior">
<endpoint address="" binding="basicHttpBinding" contract="AddonWCFWebservice.IService1"/>
<!--
<endpoint address=""
binding="webHttpBinding"
contract="AddonWCFWebservice.IService1"
behaviorConfiguration="WebBehavior"/>
-->
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"/>
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior name="MyserviceBehavior">
<!-- To avoid disclosing metadata information, set the value below to false and remove the metadata endpoint above before deployment -->
<serviceMetadata httpGetEnabled="true"/>
<!-- To receive exception details in faults for debugging purposes, set the value below to true. Set to false before deployment to avoid disclosing exception information -->
<serviceDebug includeExceptionDetailInFaults="true"/>
</behavior>
</serviceBehaviors>
<endpointBehaviors>
<behavior name="WebBehavior">
<webHttp />
</behavior>
</endpointBehaviors>
</behaviors>
</system.serviceModel>
<system.web>
<compilation debug="true"/>
<customErrors mode="Off"/>
</system.web>
</configuration>