10

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.
Is it possible to run this application without admin privilege? (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.

user554712
  • 211
  • 1
  • 3
  • 8

3 Answers3

7

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.

nitzmahone
  • 13,720
  • 2
  • 36
  • 39
  • 1
    My goal is let my program can run on a no admin right user account which never has no admin right and NO admin will help the user. That mean user can not adds a allocated URL and this problem still can't be solved. – user554712 Apr 30 '11 at 15:45
  • 1
    url format should be the same as in error you're encoutering on binding... For me it was `http:\\+:port_number\sub_url` – Ivan Temchenko Feb 26 '19 at 09:12
6

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.

RuudSieb
  • 523
  • 5
  • 13
  • 3
    this works only if `http://localhost:80/Temporary_Listen_Addresses/` is already added to the http bindings (which in most cases is already done in Standard installations) look at console when running "netsh http show urlacl" there is already an urlacl for that address (win10)! – Sebastian Nov 07 '16 at 10:58
5

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.

nitzmahone
  • 13,720
  • 2
  • 36
  • 39
  • Is there have other way to do this, if HTTP binding is not a must?( Like NetTcpBinding, NetMsmqBinding, etc.) And I have find out that using netTcpBinding binding is not requesting the admin right but it cannot be added service references in Visual Studio 2010. – user554712 May 02 '11 at 07:25
  • 1
    Works fine- see http://stackoverflow.com/questions/2335338/can-i-add-a-service-reference-with-nettcpbinding-in-wcf – nitzmahone May 03 '11 at 00:06