C# 使用WCF服务时找不到终结点元素

C# 使用WCF服务时找不到终结点元素,c#,.net,wcf,wcf-binding,C#,.net,Wcf,Wcf Binding,尝试使用WCF服务时出现以下错误我研究了这个问题,两个配置文件中的名称和合同值都是相同的 找不到名为“BasicHttpBinding_IService1”的终结点元素 并在ServiceModel客户端中约定“ServiceReference1.IService1” 配置部分。这可能是因为没有配置文件 为应用程序找到,或者因为没有匹配的端点元素 可以在客户端元素中找到此名称 WCF服务在我的解决方案中是类库,我正试图在同一解决方案下的另一个类库项目中使用它 Client.config &l

尝试使用
WCF服务时出现以下错误
<代码>我研究了这个问题,两个配置文件中的名称和合同值都是相同的

找不到名为“BasicHttpBinding_IService1”的终结点元素 并在ServiceModel客户端中约定“ServiceReference1.IService1” 配置部分。这可能是因为没有配置文件 为应用程序找到,或者因为没有匹配的端点元素 可以在客户端元素中找到此名称

WCF服务在我的解决方案中是类库,我正试图在同一解决方案下的另一个类库项目中使用它

Client.config

  <endpoint address="http://localhost:8733/Design_Time_Addresses/WcfServiceLibrary1/Service1/"
    binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_IService1"
    contract="ServiceReference1.IService1" name="BasicHttpBinding_IService1" />
</client>


WCF配置文件

<configuration>

  <appSettings>
    <add key="aspnet:UseTaskFriendlySynchronizationContext" value="true" />
  </appSettings>
  <system.web>
    <compilation debug="true" />
  </system.web>
  <!-- When deploying the service library project, the content of the config file must be added to the host's 
  app.config file. System.Configuration does not support config files for libraries. -->
  <system.serviceModel>
    <services>
      <service name="WcfServiceLibrary1.Service1">
        <host>
          <baseAddresses>
            <add baseAddress = "http://localhost:8733/Design_Time_Addresses/WcfServiceLibrary1/Service1/" />
          </baseAddresses>
        </host>
        <!-- Service Endpoints -->
        <!-- Unless fully qualified, address is relative to base address supplied above -->
        <endpoint address="" binding="basicHttpBinding" contract="WcfServiceLibrary1.IService1">
          <!-- 
              Upon deployment, the following identity element should be removed or replaced to reflect the 
              identity under which the deployed service runs.  If removed, WCF will infer an appropriate identity 
              automatically.
          -->
          <identity>
            <dns value="localhost"/>
          </identity>
        </endpoint>
        <!-- Metadata Endpoints -->
        <!-- The Metadata Exchange endpoint is used by the service to describe itself to clients. --> 
        <!-- This endpoint does not use a secure binding and should be secured or removed before deployment -->
        <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"/>
      </service>
    </services>
    <behaviors>
      <serviceBehaviors>
        <behavior>
          <!-- To avoid disclosing metadata information, 
          set the values below to false before deployment -->
          <serviceMetadata httpGetEnabled="True" httpsGetEnabled="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="False" />
        </behavior>
      </serviceBehaviors>
    </behaviors>
  </system.serviceModel>

</configuration>

我认为您的问题正如您在问题中所说的“
您试图使用类库中的服务,并从另一个项目调用类库。”
有关原始答案,请参阅此链接

要解决您的问题,您只需要将客户机绑定详细信息复制到主调用者项目配置文件

  <system.serviceModel>
    <bindings>
      <basicHttpBinding>
        <binding name="BasicHttpBinding_IService1" />
      </basicHttpBinding>
    </bindings>
    <client>
      <endpoint address="http://localhost:8733/Design_Time_Addresses/WcfServiceLibrary1/Service1/"
        binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_IService1"
        contract="ServiceReference1.IService1" name="BasicHttpBinding_IService1" />
    </client>
  </system.serviceModel>

我认为您的问题正如您在问题中所说的“
您试图使用类库中的服务,并从另一个项目调用类库。”
有关原始答案,请参阅此链接

要解决您的问题,您只需要将客户机绑定详细信息复制到主调用者项目配置文件

  <system.serviceModel>
    <bindings>
      <basicHttpBinding>
        <binding name="BasicHttpBinding_IService1" />
      </basicHttpBinding>
    </bindings>
    <client>
      <endpoint address="http://localhost:8733/Design_Time_Addresses/WcfServiceLibrary1/Service1/"
        binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_IService1"
        contract="ServiceReference1.IService1" name="BasicHttpBinding_IService1" />
    </client>
  </system.serviceModel>

尝试为您的服务名称和合同使用完整名称空间的全名标识符

<service name="SOLUTIONNAME.WcfServiceLibrary1.Service1">
     <endpoint address="" binding="basicHttpBinding" 
     contract="SOLUTIONNAME.WcfServiceLibrary1.IService1">
     ...

 </service>

...

尝试为您的服务名称和合同使用完整名称空间的全名标识符

<service name="SOLUTIONNAME.WcfServiceLibrary1.Service1">
     <endpoint address="" binding="basicHttpBinding" 
     contract="SOLUTIONNAME.WcfServiceLibrary1.IService1">
     ...

 </service>

...

您是否可以看到该服务在浏览器中可用?它在浏览器中可用。您是否可以看到该服务在浏览器中可用?它在浏览器中可用。让我看看这是否可以解决问题。让我看看这是否可以解决问题。