作为NetworkService运行时WCF EndpointNotFoundException

时间:2014-07-16 06:39:34

标签: c# wcf net.pipe

我有一个由IIS托管的net.Pipe WCF服务(现在,在我的VS2010中): (Global.asax中):

 protected void Application_Start()
{
  AreaRegistration.RegisterAllAreas();

  WebApiConfig.Register(GlobalConfiguration.Configuration);
  FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
  RouteConfig.RegisterRoutes(RouteTable.Routes);

  ServiceHost svcHost = new ServiceHost(typeof(DoSomethingService), new Uri("net.pipe://localhost/helloworld"));
  var serviceBinding = new NetNamedPipeBinding { MaxReceivedMessageSize = int.MaxValue, MaxConnections = 2048 };
  var sect = new NamedPipeTransportSecurity { ProtectionLevel = ProtectionLevel.EncryptAndSign };
  var sec = new NetNamedPipeSecurity { Mode = NetNamedPipeSecurityMode.Transport, Transport = sect };
  serviceBinding.Security = sec;

  svcHost.AddServiceEndpoint(typeof(IDoSomethingContract), serviceBinding, "");
  svcHost.Open();
}

我有一个控制台应用客户端:

static void Main(string[] args)
{
  var factory = new ChannelFactory<IDoSomethingContract>();

  var defaultCredentials = factory.Endpoint.Behaviors.Find<ClientCredentials>();
  factory.Endpoint.Behaviors.Remove(defaultCredentials); 
  factory.Credentials.Windows.AllowedImpersonationLevel = TokenImpersonationLevel.Impersonation;
  factory.Credentials.Windows.ClientCredential = CredentialCache.DefaultNetworkCredentials;
  var serviceBinding = new NetNamedPipeBinding { MaxReceivedMessageSize = int.MaxValue, MaxConnections = 2048 };
  var sect = new NamedPipeTransportSecurity { ProtectionLevel = ProtectionLevel.EncryptAndSign };
  var sec = new NetNamedPipeSecurity { Mode = NetNamedPipeSecurityMode.Transport, Transport = sect };
  serviceBinding.Security = sec;
  var ep = new EndpointAddress("net.pipe://localhost/helloworld");
  factory.Endpoint.Binding = serviceBinding;
  var love = factory.CreateChannel(ep); 
  Console.WriteLine(love.Do());

  Console.ReadKey();
}

现在,当我作为用户主体运行时,一切都很好(所以我可以在我的操作中使用PrincipalPermission)。

但是,如果我创建一个网络服务&#39;命令行提示符(使用psexec),并尝试运行客户端(显然运行服务),我得到EndpointNotFoundException异常。

网络服务是否需要做任何事情来查看我的命名管道?

2 个答案:

答案 0 :(得分:1)

答案 1 :(得分:0)

我正在考虑删除这个,但是因为有人实际评论过 - 我在这里找到了答案: http://social.msdn.microsoft.com/Forums/vstudio/en-US/fcb7254a-15b5-4be4-bf67-34d500bdce2d/wcf-netpipe-endpoint-not-found-exception-whitout-elevated-user-rights-uac-enabled?forum=wcf

基本上,由于我将自己的开发服务器作为自己的帐户运行,因此该服务已在会话命名空间中发布。一旦我在真正的IIS上将其作为网络服务发布,它就可以在全局命名空间中看到,所以我可以看到它。

相关问题