0

我有一个由 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)。

但是,如果我为自己创建一个“网络服务”命令行提示符(使用 psexec),并尝试运行客户端(显然,服务正在运行),我会收到 EndpointNotFoundException 异常。

为了让网络服务看到我的命名管道,我需要做些什么吗?

4

2 回答 2

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

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

于 2014-07-16T06:58:29.773 回答