Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/289.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 服务可以';在WCF中找不到其他服务的终结点_C#_Wcf_Iis_Service - Fatal编程技术网

C# 服务可以';在WCF中找不到其他服务的终结点

C# 服务可以';在WCF中找不到其他服务的终结点,c#,wcf,iis,service,C#,Wcf,Iis,Service,我正在尝试创建两个WCF服务,它们应该能够相互访问。但是,我收到以下错误消息: 服务器在处理请求时遇到错误。异常消息是“在ServiceModel客户端配置部分中找不到引用约定“AddonWCFService.IService1”的默认终结点元素”。这可能是因为找不到应用程序的配置文件,或者在客户端元素中找不到与此约定匹配的端点元素。“ 我从这个服务调用Test()方法 namespace CustomersService { [ServiceContract] public i

我正在尝试创建两个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的同一个active directory中。我使用web URL将服务引用添加到VS C#项目中,即

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

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

这一行在这里:


将合约指定为“AddonWCFWebservice.IService1”,而它应该类似于“AddonService.IService1”(不带“WCF”)

配置的问题在于没有客户端配置。您只有服务器部件。您需要有带有端点的客户端元素。请看这里:

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

我将服务引用的命名空间更改为AddonWCFWebservice,就像在我的项目文件中一样。错误仍然存在,但现在出现了“在ServiceModel客户端配置部分中找不到引用约定'AddonWCFService.IService1'的默认端点元素”。正如您所看到的,这是web.config。这是否与两个服务都位于同一个IIS active directory中有关?有关于如何调试这个的提示吗?对!非常感谢。这就成功了。不知道有一个客户部门。现在我理解了错误消息,它实际上非常清楚:“[…]ServiceModel客户端配置部分”。现在要了解如何解决此错误:“ChannelFactory的端点必须指定有效地址”由于此答复,我的代码现在可以正常工作,请参阅问题中的解决方案。