2011-04-25 135 views
7

我寫了一個託管WCF服務的應用程序。 我試着用這個配置運行應用程序。沒有UAC /管理員權限的主機WCF應用程序

<?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> 

但它導致應用程序需要以管理員身份運行。
是否可以在沒有管理員權限的情況下運行此應用程序?(如果可能,只更改配置。)另外,我還需要在Visual Studio中添加服務引用來編寫客戶端程序。如果可能的話,請保持應用程序可以在Visual Studio 2010中

回答

5

增值服務引用如果你想保持它的HTTP綁定,一個非管理員可以運行它,你需要使用命令

添加權限
netsh http add urlacl (see help for the rest of the params) 

這將允許您指定的用戶切割機器的URL空間塊。如果您不想這樣做,則需要更改爲不需要特殊權限才能偵聽的其他綁定(例如netTcp)。

+1

我的目標是讓我的程序可以在沒有管理員權限的用戶帳戶上運行,並且沒有管理員可以幫助用戶。這意味着用戶不能添加分配的URL,但這個問題仍然無法解決。 – user554712 2011-04-30 15:45:09

4

根據對我的其他答案的評論,您將無法使用內置的HTTP綁定完成此操作 - 它們都基於HTTP.sys,這需要授予非管理員權限用戶註冊URL。如果您的部署方案允許,請考慮切換到netTcpBinding,而不是那裏的權限問題。否則,你就是帶有內置綁定的SOL - 你需要構建一個不基於HTTP.sys的原始HTTP傳輸。

+1

這不應該編輯爲您的原始答案? – 2011-05-01 09:52:08

+0

是否有其他的方式來做到這一點,如果HTTP綁定不是必須的?(像NetTcpBinding,NetMsmqBinding等)我已經發現,使用netTcpBinding綁定沒有請求管理權限,但它不能添加服務引用Visual Studio 2010. – user554712 2011-05-02 07:25:52

+1

工作正常 - 請參閱http://stackoverflow.com/questions/2335338/can-i-add-a-service-reference-with-nettcpbinding-in-wcf – nitzmahone 2011-05-03 00:06:28

2

該解決方案爲我工作(使用HTTP綁定),打開這個網址服務:

http://localhost:80/Temporary_Listen_Addresses/ 

必須承認,我以後-ING谷歌在一段時間發現在這個網站上http://www.paraesthesia.com/archive/2010/06/11/developing-as-a-non-admin-testing-wcf-services.aspx/ ...所以信貸給那個傢伙。

+1

這隻適用於'http:// localhost:80/Temporary_Listen_Addresses /'已經添加到http綁定(在大多數情況下已經在標準安裝中完成),在運行「netsh http show urlacl」時看到控制檯已經有一個用於該地址的urlacl(win10)! – Sebastian 2016-11-07 10:58:40

相關問題