简体   繁体   English

如何在没有管理员权限的情况下发布并连接到我自己的WCF终结点

[英]How to publish and connect to my own WCF endpoint without Admin rights

I have a WCF REST API implemented in a C# class library. 我在C#类库中实现了WCF REST API。 Ultimately I would like the service to be able to be hosted in my own process, or as a Windows service, depending on the user's choice. 最终,我希望能够根据自己的选择将服务托管在自己的进程中,或者作为Windows服务托管。 So it needs to support both inproc and HTTP bindings. 因此,它需要同时支持inproc和HTTP绑定。

The following works as admin, but not as a regular user (says it doesn't have rights to open up the HTTP port). 以下内容以管理员身份工作,但不以普通用户身份工作(例如,它无权打开HTTP端口)。

What's my next step? 我下一步是什么? Should I be using a different protocol for in-proc? 我应该对进程使用其他协议吗? So long as I retain the ability to have it cross-machine on the HTTP binding, I'm satisfied. 只要我保留在HTTP绑定中跨机器运行的能力,我就会感到满意。

        WebServiceHost host = new WebServiceHost(typeof(SapphireServiceLib.SapphireService), new Uri("http://localhost:8080/") );
        try
        {
            ServiceEndpoint ep = host.AddServiceEndpoint(typeof(SapphireServiceLib.ISapphireService), new WebHttpBinding(), "");
            host.Open();
        }
        catch (Exception ex)
        {
            MessageBox.Show("Unable to start Sapphire Service Host: " + ex.Message);
            return;
        }

        // Next, connect to the endpoint for our own use

        try
        {
            // Set the max msg large, otherwise max size would be 64K and we couldn't fetch all the logs.
            // REVIEW I suppose this might expose it to a Denial of Service attack if public

            var binding = new WebHttpBinding() { MaxReceivedMessageSize = Int32.MaxValue };

            ChannelFactory<ISapphireService> cf = new ChannelFactory<ISapphireService>(binding, "http://localhost:8080");
            cf.Endpoint.Behaviors.Add(new WebHttpBehavior());
            SapphireService = cf.CreateChannel();
        }
        catch (Exception ex)
        {
            MessageBox.Show("Unable to connect to service endpoint: " + ex.Message);
            return;
        }

If you want to keep the http binding you have to use the netsh http add urlacl url=http://+80/YourService command to allow a process without admin rights to use it. 如果要保留http绑定,则必须使用netsh http add urlacl url=http://+80/YourService命令来允许没有管理员权限的进程使用它。

Another option is to switch to netTcpBinding for instance. 另一个选择是例如切换到netTcpBinding。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何使用InstallShield发布.exe,以便它不要求管理员权限? - How to publish an .exe with InstallShield, so that it does not ask for admin rights? 如何在没有管理员权限的情况下安装我的C#应用​​程序? - How Do I Make My C# Application Install Without Admin Rights? 在没有管理员权限的情况下自动更新Vista中的.NET应用程序 - automatically update my .NET application in Vista without admin rights 如何在C#中没有管理员权限的情况下重新启动IIS - How To Restart IIS without Admin Rights in C# 如何在没有我的WPF主机的情况下启动具有管理员权限的进程,并且还运行管理员权限以实现文件拖放? - How do I start a process with administrator privileges without my WPF host also runs with admin rights in order to implement file drag & drop? 如何授予我的 Windows 服务管理员权限 - How do I give my windows service admin rights 发布WCF的非https终结点-Azure - Publish a non https endpoint for WCF - Azure 有没有办法与minifilter沟通而不需要管理员权限? - Is there a way to communicate with a minifilter without requiring admin rights? 在 Visual Studio 中调试没有管理员权限的应用程序 - Debug application without admin rights in Visual Studio 在没有管理员权限的情况下启动IIS Express - Starting IIS Express without admin rights
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM