简体   繁体   中英

Host WCF application without UAC/admin privilege

I have written a application which is hosting a WCF Service. And I try to run the application with this config.

<?xml version="1.0"?>
<configuration>
    <system.serviceModel>
        <services>
            <service name="MyApp.Service" behaviorConfiguration="ServiceBehavior">
                <host>
                    <baseAddresses>
                        <add baseAddress="http://localhost:8000/service"/>
                    </baseAddresses>
                </host>
                <endpoint address="" binding="wsHttpBinding" contract="MyApp.IService"/>
                <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"/>
            </service>
        </services>
        <behaviors>
            <serviceBehaviors>
                <behavior name="ServiceBehavior">
                    <serviceMetadata httpGetEnabled="true"/>
                    <serviceDebug includeExceptionDetailInFaults="False"/>
                </behavior>
            </serviceBehaviors>
        </behaviors>
    </system.serviceModel>
<startup><supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0"/></startup></configuration>

But it cause the application need to run as administrator.
(If possible, change the config only.) In addition, I also need to add service references in Visual Studio to write a client program. If possible, please keep the application can be added service references in Visual Studio 2010.

If you want to keep it on an HTTP binding so a nonadmin can run it, you'll need to add permissions using the command

netsh http add urlacl (see help for the rest of the params)

This will allow the user you specify to carve off a chunk of the URL-space for the machine. If you don't want to do this, you'll need to change to a different binding (netTcp, for instance) that doesn't require special privileges to listen.

This solution worked for me (using HTTP binding), open your service on this URL:

http://localhost:80/Temporary_Listen_Addresses/

Must admit that i found it on this site http://www.paraesthesia.com/archive/2010/06/11/developing-as-a-non-admin-testing-wcf-services.aspx/ after google-ing for some time...So credits to that guy.

Based on the comment to my other answer, you won't be able to do this with the built-in HTTP bindings- they're all based on HTTP.sys, which requires rights to be granted to non-admin users to register URLs. If your deployment scenario allows, consider switching to netTcpBinding instead- no permission issues there. Otherwise, you're SOL with the built-in bindings- you'd need to build a raw HTTP transport that's not based on HTTP.sys.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM