Сервис не может найти конечную точку другого сервиса в WCF - PullRequest
2 голосов
/ 21 декабря 2011

Я пытаюсь создать две службы 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>

Ответы [ 2 ]

3 голосов
/ 22 декабря 2011

Проблема с вашим конфигом в том, что у вас нет клиентских конфигураций.У вас есть только серверные части.Вам нужен элемент client с конечными точками.Взгляните сюда: http://msdn.microsoft.com/en-us/library/ms731745.aspx

Если вы не уверены в своих навыках настройки, я бы посоветовал вам открыть конфигурацию с помощью SvcConfigEditor.exe.Вы сразу увидите, что настроено.Вы можете найти его здесь: C: \ Program Files \ Microsoft SDKs \ Windows \ v6.0A \ Bin \ SvcConfigEditor.exe.Если вы это сделаете - вы увидите, что нет настроенных клиентов

0 голосов
/ 21 декабря 2011

Я думаю, что вы указали неправильный сервисный контракт в вашем конфигурационном файле.

Эта строка здесь:

<endpoint address="" binding="wsHttpBinding" contract="AddonWCFWebservice.IService1"/>

определяет контракт как "AddonWCFWebservice.IService1", когда он должен быть чем-то вроде "AddonService.IService1" (без "WCF").

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...