在WCF中使用命名管道,抛出PipeException?

时间:2012-03-21 18:46:06

标签: wcf named-pipes

尽管有很多搜索和阅读文章,例如:Exploring the WCF Named Pipe Binding - Part 1(第2部分和第3部分),但我无法使我的服务正常运作。

这是我的配置:

<system.serviceModel>
  <client>
    <endpoint address="net.pipe://localhost/GlobalPositioningService"
              binding="netNamedPipeBinding" 
              contract="GI.Services.GlobalPositioning.Contracts.IGlobalPositioning" />
  </client>
  <services>
    <service name="GI.Services.GlobalPositioning.Services.GlobalPositioningService">
      <endpoint address=""
                binding="wsHttpBinding"
                contract="GI.Services.GlobalPositioning.Contracts.IGlobalPositioning">
        <identity>
          <dns value="localhost" />
        </identity>
      </endpoint>
      <endpoint address="net.pipe://localhost/GlobalPositioningService"
                binding="netNamedPipeBinding"
                contract="GI.Services.GlobalPositioning.Contracts.IGlobalPositioning" />
      <host>
        <baseAddresses>
          <add baseAddress="http://localhost:8080/GlobalPositioningService/"/>
        </baseAddresses>
      </host>
    </service>
  </services>

然后,我尝试通过命名管道测试我的服务:

[TestFixture]
public class GlobalPositioningServiceTests {
    [TestFixtureSetUp]
    public void SetUpHost() {
        var channelFactory = new ChannelFactory<IGlobalPositioning>(binding, new EndpointAddress(address));
        channelFactory.Open();
        service = channelFactory.CreateChannel();
    }

    private const string address = "net.pipe://localhost/GlobalPositioningService";
    private static readonly Binding binding = new NetNamedPipeBinding();
    private static IGlobalPositioning service;
}

我还尝试了另一种使用ServiceHost实例的方法:

    [TestFixtureSetUp]
    public void SetUpHost() {
        host = new ServiceHost(typeof(GlobalPositioningService));
        host.AddServiceEndpoint(typeof(IGlobalPositioning), binding, address);
        host.Open();
        service = new GlobalPositioningService();
    }

我总是通过堆栈跟踪获得此错误:

  

错误2测试'GI.Services.GlobalPositioning.Services.Tests.GlobalPositioningServiceTests.GetGlobalPositionWorksWithDiacriticsInMunicipalityName(“143,rue Marcotte,Sainte-Anne-de-la-P \ x00E9rade”,46.5736528d,-72.2021346d)'失败:       System.ServiceModel.EndpointNotFoundException:net.pipe:// localhost / GlobalPositioningService上没有可以接受该消息的端点。这通常是由错误的地址或SOAP操作引起的。有关更多详细信息,请参阅InnerException(如果存在)。     ----&GT; System.IO.PipeException:在本地计算机上找不到管道端点'net.pipe:// localhost / GlobalPositioningService'。

     

服务器堆栈跟踪:   在System.ServiceModel.Channels.PipeConnectionInitiator.GetPipeName(Uri uri)   在System.ServiceModel.Channels.NamedPipeConnectionPoolRegistry.NamedPipeConnectionPool.GetPoolKey(EndpointAddress地址,Uri via)   在System.ServiceModel.Channels.CommunicationPool`2.TakeConnection(EndpointAddress地址,Uri via,TimeSpan超时,TKey&amp;键)   在System.ServiceModel.Channels.ConnectionPoolHelper.EstablishConnection(TimeSpan超时)   在System.ServiceModel.Channels.ClientFramingDuplexSessionChannel.OnOpen(TimeSpan超时)   在System.ServiceModel.Channels.CommunicationObject.Open(TimeSpan超时)   在System.ServiceModel.Channels.ServiceChannel.OnOpen(TimeSpan超时)   在System.ServiceModel.Channels.CommunicationObject.Open(TimeSpan超时)   在System.ServiceModel.Channels.ServiceChannel.CallOpenOnce.System.ServiceModel.Channels.ServiceChannel.ICallOnce.Call(ServiceChannel频道,TimeSpan超时)   在System.ServiceModel.Channels.ServiceChannel.CallOnceManager.CallOnce(TimeSpan超时,CallOnceManager级联)   在System.ServiceModel.Channels.ServiceChannel.EnsureOpened(TimeSpan超时)   在System.ServiceModel.Channels.ServiceChannel.Call(String action,Boolean oneway,ProxyOperationRuntime operation,Object [] ins,Object [] outs,TimeSpan timeout)   在System.ServiceModel.Channels.ServiceChannelProxy.InvokeService(IMethodCallMessage methodCall,ProxyOperationRuntime操作)   在System.ServiceModel.Channels.ServiceChannelProxy.Invoke(IMessage message)

     

在[0]处重新抛出异常:   在System.Runtime.Remoting.Proxies.RealProxy.HandleReturnMessage(IMessage reqMsg,IMessage retMsg)   在System.Runtime.Remoting.Proxies.RealProxy.PrivateInvoke(MessageData&amp; msgData,Int32 type)   在GI.Services.GlobalPositioning.Contracts.IGlobalPositioning.GetGlobalPosition(String mailingAddress)   在GI.Services.GlobalPositioning.Services.Tests.GlobalPositioningServiceTests.GetGlobalPositionWorksWithDiacriticsInMunicipalityName(字符串地址,双纬度,双经度)在C:\ Open \ Projects \ Framework \ Src \ GI.Services \ GI.Services.GlobalPositioning.Services.Tests \ GlobalPositioningServiceTests.cs:第27行   --PipeException C:\ Open \ Projects \ Framework \ Src \ GI.Services \ GI.Services.GlobalPositioning.Services.Tests \ GlobalPositioningServiceTests.cs 27

有关您的信息,我正在使用:

  1. Visual Studio 2010
  2. Windows 7
  3. NUnit的
  4. 我的服务包含在WCF服务库中。

1 个答案:

答案 0 :(得分:1)

您似乎正在尝试使用netNamedPipesBinding对正在运行的服务实例进行集成测试。为此,您需要同时拥有提供服务实例的服务主机和用于调用服务的服务代理实例。您可以尝试将两个示例TestFixtureSetup方法中的代码组合在一起,以便实例化服务主机和服务代理(CreateChannel方法的结果)。有关如何执行此操作的示例,请查看此blog post