c# – System.ServiceModel.AddressAccessDeniedException:HTTP無法註冊URL http :: 8080
我建立了我的第一個自主的wcf服務.我託管在C#控制檯應用程式,但它丟擲錯誤:* TSystem.ServiceModel.AddressAccessDeniedException:HTTP不能註冊URL http:8080
當我執行Visual 2013作為管理員,那麼它的工作很好,但不是如果我沒有.所以任何方式自動完成它,而不是啟動VS作為ADMIN.
到目前為止,我建立了HellloService類庫,其中我添加了WCFService,它包含一個interfaceIHelloService.cs和HelloService.cs
IHelloService:
namespace HellloService { [ServiceContract] public interface IHelloService { [OperationContract] String GetMsg(); } }
HelloService的:
namespace HellloService { public class HelloService : IHelloService { public String GetMsg() { return "Service Accessed"; } } }
然後我建立了具有app.config檔案的C#控制檯應用程式“HellloServiceHost”:
的app.config:
<?xml version="1.0" encoding="utf-8" ?> <configuration> <system.serviceModel> <behaviors> <serviceBehaviors > <behavior name="MexBehaviour"> <serviceMetadata httpGetEnabled="true"/> </behavior> </serviceBehaviors> </behaviors> <services> <service name="HellloService.HelloService" behaviorConfiguration="MexBehaviour" > <endpoint address="HelloService" binding="basicHttpBinding" contract="HellloService.IHelloService"></endpoint> <endpoint address="HelloService" binding="netTcpBinding" contract="HellloService.IHelloService"></endpoint> <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"></endpoint> <host> <baseAddresses> <add baseAddress="http://localhost:8080/"/> <add baseAddress="net.tcp://localhost:8081/"/> </baseAddresses> </host> </service> </services> </system.serviceModel> </configuration>
和program.cs檔案:
using HellloService; using System.ServiceModel; namespace HellloServiceHost { class Program { static void Main(string[] args) { using(ServiceHost sh = new ServiceHost(typeof(HellloService.HelloService))) { sh.Open(); Console.WriteLine("Host Started @"+ System.DateTime.UtcNow.ToShortDateString()); sh.Close(); } } } }
我遵循視訊教程,但它不工作為什麼?
我正在使用VS 2013,.net 4
在另一個專案中遇到同樣的問題.
問題是繫結到tcp埠需要管理許可權.有幾種方法來處理這個問題.
>保持管理命令提示符開啟.那麼你可以直接執行控制檯應用程式.
>(如您所建議的)以管理員身份執行VS.這隻有在除錯你的應用程式時才是絕對必要的.
>建立一個應用程式顯示檔案,指定requestedExecutionLevel level =“requireAdministrator”.詳見ofollow,noindex" target="_blank">How to force my .NET App to run as administrator on Windows+7/">Windows 7? .
http://stackoverflow.com/questions/22686469/system-servicemodel-addressaccessdeniedexception-http-could-not-register-url-ht