C# 同一程序集中WCF客户端的EndpointNotFoundException

C# 同一程序集中WCF客户端的EndpointNotFoundException,c#,.net,wcf,C#,.net,Wcf,我正在WPF应用程序中托管一个WCF服务,并希望在同一程序集中使用它(不过,在另一个实例中)。为了进行依赖项注入,我正在调用ServiceHost.Open,其中包含已创建的服务实现实例 合同和服务执行 App.config 打开ServiceHost后,它将侦听端口61000(通过netstat检查)。尽管我不需要它(因为我自己创建了一个实现iSeries的客户机),但我测试了创建一个服务引用,结果成功了 但是,我的服务实现如下所示: public class ServiceClient :

我正在WPF应用程序中托管一个WCF服务,并希望在同一程序集中使用它(不过,在另一个实例中)。为了进行依赖项注入,我正在调用
ServiceHost.Open
,其中包含已创建的服务实现实例

合同和服务执行 App.config 打开
ServiceHost
后,它将侦听端口61000(通过netstat检查)。尽管我不需要它(因为我自己创建了一个实现iSeries的客户机),但我测试了创建一个服务引用,结果成功了

但是,我的服务实现如下所示:

public class ServiceClient : ClientBase<IService>, IService
{
    public ServiceClient(string endpointConfigurationName, EndpointAddress remoteAddress) :
            base(endpointConfigurationName, remoteAddress)
    {
    }

    public PartnerInfo GetPartnerInfo()
    {
        return Channel.GetPartnerInfo();
    }
}
我的
ServiceClient
实现中是否缺少一些内容,因为我在同一个程序集中有服务和客户端,因此不想在Visual Studio中创建服务引用

更新 我测试了创建服务引用的整个过程。这也不行。我还仔细检查了我的防火墙规则。以下是异常消息:

网络上没有端点侦听。tcp://192.168.200.29:61000/Project/Service.svc 这可以接受这个信息。这通常是由不正确的地址或SOAP操作引起的。有关更多详细信息,请参阅InnerException(如果存在)。

更新2
出于测试目的,我创建了第二个
wsHttpBinding
端点。这一个可以在我的浏览器中访问,因此服务已启动并运行。

经过数小时的调试,我自己解决了(非常简单)的问题:

事实证明,服务URL不是
net。tcp://localhost:61000/Project/Service.svc
但是
网络。tcp://localhost:61000/Project/Service.svc/endpoint0

从我的端点配置中删除“endpoint0”后,连接进行得很顺利:

<endpoint address=""
          binding="netTcpBinding"
          bindingConfiguration="NetTcpBinding_IService"
          contract="Project.WebService.IService">
  <!-- -->
</endpoint>

经过数小时的调试,我自己解决了(非常简单的)问题:

事实证明,服务URL不是
net。tcp://localhost:61000/Project/Service.svc
但是
网络。tcp://localhost:61000/Project/Service.svc/endpoint0

从我的端点配置中删除“endpoint0”后,连接进行得很顺利:

<endpoint address=""
          binding="netTcpBinding"
          bindingConfiguration="NetTcpBinding_IService"
          contract="Project.WebService.IService">
  <!-- -->
</endpoint>

public class ServiceClient : ClientBase<IService>, IService
{
    public ServiceClient(string endpointConfigurationName, EndpointAddress remoteAddress) :
            base(endpointConfigurationName, remoteAddress)
    {
    }

    public PartnerInfo GetPartnerInfo()
    {
        return Channel.GetPartnerInfo();
    }
}
Uri baseUri = new Uri("net.tcp://<IPAdress>:61000");
Uri uri = new Uri(baseUri, "Project/Service.svc");

// Spn identity is only here for testing purposes, doesn't work either way
return new ServiceClient("NetTcpBinding_IService", new EndpointAddress(uri, EndpointIdentity.CreateSpnIdentity("NetTcpBinding_IService")));
<endpoint address=""
          binding="netTcpBinding"
          bindingConfiguration="NetTcpBinding_IService"
          contract="Project.WebService.IService">
  <!-- -->
</endpoint>