【问题标题】:Service can't find endpoint of other service in WCF服务在 WCF 中找不到其他服务的端点
【发布时间】:2012-01-25 09:32:24
【问题描述】:

我正在尝试创建两个应该能够相互访问的 WCF 服务。但是我收到此错误消息: 服务器在处理请求时遇到错误。异常消息是“在 ServiceModel 客户端配置部分中找不到引用合同“AddonWCFService.IService1”的默认端点元素。这可能是因为没有为您的应用程序找到配置文件,或者因为在客户端元素中找不到与此合同匹配的端点元素。

我从这个服务调用 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()
        {

        }
    }
}

我的网络配置:

<?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 的同一个活动目录中。我使用 Web URL 将服务引用添加到 VS C# 项目,即http://www.foobar.baz/Test/Service1.svc 和 http://www.foobar.baz/Test/Customers.svc

这可能是显而易见的,但我对整个 WCF 业务还很陌生。谢谢!

更新:解决方案是在我的 webconfig 中添加一个客户端部分。此外,我在 wsHttpBinding 上使用了 basicHttpBinding,因为我的安全性将在其他地方合并,因为它是一项公共服务。我必须将客户端的绑定与服务部分的绑定相匹配:两者都是 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>

【问题讨论】:

    标签: c# wcf iis service


    【解决方案1】:

    我认为您在配置文件中指定了错误的服务合同。

    这里的这一行:

    &lt;endpoint address="" binding="wsHttpBinding" contract="AddonWCFWebservice.IService1"/&gt;

    当它应该类似于“AddonService.IService1”(没有“WCF”)时,将合同指定为“AddonWCFWebservice.IService1”。

    【讨论】:

    • 我在项目文件中将服务引用的命名空间更改为 AddonWCFWebservice。错误仍然存​​在,但现在出现“在 ServiceModel 客户端配置部分中找不到引用合同‘AddonWCFService.IService1’的默认端点元素。”如您所见,这个 IS 是 web.config。这是否与这两个服务都在同一个 IIS 活动目录中的事实有关?关于如何调试的任何指示?
    【解决方案2】:

    您的配置的问题是您没有客户端配置。您只有服务器部件。您需要有带有端点的 client 元素。看这里:http://msdn.microsoft.com/en-us/library/ms731745.aspx

    如果您对自己的配置技能不太确定,我建议您使用 SvcConfigEditor.exe 打开您的配置。您将立即看到已配置的内容。 您可以在此处找到它:C:\Program Files\Microsoft SDKs\Windows\v6.0A\Bin\SvcConfigEditor.exe。 如果你愿意 - 你会看到没有配置客户端

    【讨论】:

    • 对!谢谢!那成功了。不知道有一个客户部分。现在我理解了错误消息,实际上很清楚:“[...] ServiceModel 客户端配置部分”。现在要弄清楚如何解决这个错误:“ChannelFactory's Endpoint must have a valid Address specified”
    • 感谢此回复,我的代码现在可以正常工作,请参阅问题中的解决方案。
    猜你喜欢
    • 2019-12-10
    • 2012-06-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-05-07
    • 2015-11-02
    • 2015-04-05
    相关资源
    最近更新 更多