4

System.ServiceModel.dll を使用する ac# アプリがあります。アプリをローカルで実行できますが、Power Shell を使用してリモートで実行しようとすると、ハングします。

問題を再現するための簡単なコードを次に示します。

    using System;
    using System.ServiceModel;
    using System.ServiceModel.Discovery;

    namespace PowerShellSecurity
    {
        class Program
        {
            static void Main(string[] args)
            {
                var serviceUri = "net.pipe://localhost/Foo/Bar";
                var discoveryUri = new Uri("soap.udp://239.255.255.250:3702/");

                var service = new MyService();

                var serviceHost = new ServiceHost(service, new Uri(serviceUri));
                serviceHost.Description.Behaviors.Add(new ServiceDiscoveryBehavior());
                serviceHost.AddServiceEndpoint(new UdpDiscoveryEndpoint(discoveryUri));
                serviceHost.AddServiceEndpoint(typeof(IMyService), new NetNamedPipeBinding(), serviceUri);

                serviceHost.Open();

                Console.WriteLine("It worked!");
            }
        }

        [ServiceContract]
        public interface IMyService
        {
            [OperationContract]
            void DoStuff();
        }

        [ServiceBehavior(InstanceContextMode = InstanceContextMode.Single, ConcurrencyMode = ConcurrencyMode.Multiple)]
        public class MyService : IMyService
        {
            public void DoStuff()
            {
                throw new NotImplementedException();
            }
        }
    }

ローカルホストで実行でき、動作します。しかし、別のホストから次の powershell コマンドを実行すると:

icm -ComputerName myHost -ScriptBlock {iex "& 'c:\Users\me\Documents\Visual Studio 2013\Projects\PowerShellSecurity\PowerShellSecurity\bin\Debug\PowerShellSecurity.exe'"}

procexp を使用して、myHost でプロセスがハングしていることを確認できます。

次に、ビジュアル スタジオを使用してこのプロセスにアタッチしました。

Power Shell を使用してアプリケーションをリモートで実行する必要がある場合、この問題を解決するにはどうすればよいですか?

どうもありがとうございました!

4

1 に答える 1