服务无法在WCF中找到其他服务的端点

时间:2011-12-21 15:16:40

标签: c# wcf iis service

我正在尝试创建两个应该能够相互访问的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的同一个活动目录中。我使用网址(即http://www.foobar.baz/Test/Service1.svchttp://www.foobar.baz/Test/Customers.svc

添加了对VS C#项目的服务引用

这可能是显而易见的事情,但我对整个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>

2 个答案:

答案 0 :(得分:3)

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

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

答案 1 :(得分:0)

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

这一行:

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

将合同指定为&#34; AddonWCFWebservice.IService1&#34;什么时候应该像&#34; AddonService.IService1&#34; (没有&#34; WCF&#34;)。