System.ServiceModel.AddressAccessDeniedException:HTTP不能注册网址HTTP :: 8080 [英] System.ServiceModel.AddressAccessDeniedException: HTTP could not register URL http::8080

查看:561
本文介绍了System.ServiceModel.AddressAccessDeniedException:HTTP不能注册网址HTTP :: 8080的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经创建了我的第一个自托管WCF服务。我主持在C#控制台应用程序,但它抛出错误: * TSystem.ServiceModel.AddressAccessDeniedException:HTTP无法注册URL为http:8080 $ B $当我运行可视化2013年以管理员身份运行则b它的工作原理好但如果我不。因此,为了得到它自动完成的,而不是启动VS作为ADMIN的任何方式。

i have created my first Self Hosted wcf service. I hosted it in C# console app but it throws error: *TSystem.ServiceModel.AddressAccessDeniedException: HTTP could not register URL http: 8080 when i run Visual 2013 as RUN AS ADMINISTRATOR then it works well but not if i don't. So any way to get it done automatically instead of starting VS as an ADMIN.

到目前为止,我创建HellloService类库中,我加入WCFService它由interfaceIHelloService.cs的和HelloService.cs

So far i created HellloService class library in which i added WCFService which consists of an interfaceIHelloService.cs and HelloService.cs

IHelloService:

IHelloService:

namespace HellloService
{

    [ServiceContract]
    public interface IHelloService
    {
        [OperationContract]
        String GetMsg();
    }
}



HelloService的:

HelloService:

namespace HellloService
{

    public class HelloService : IHelloService
    {
        public String GetMsg()
        {
            return "Service Accessed";
        }
    }
}



然后我创建的C#控制台应用程序HellloServiceHost'里面有app.config文件:

then i created C# Console App 'HellloServiceHost' which has app.config file:

的app.config:

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的文件:

and program.cs file:

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();
            }
        }
    }
}



我跟着视频教程完全相同,但它不工作,为什么?

i followed video tutorial exactly but it's not working why ?

我使用VS 2013的.NET 4

i am using VS 2013, .net 4

推荐答案

我遇到了一个不同的项目相同的问题。

I ran into the same problem on a different project.

的问题是绑定到一个TCP端口需​​要管理权限。有一对夫妇的方式来处理这个问题。

The problem is that binding to a tcp port requires administrative privileges. There's a couple ways to deal with this.


  1. 请管理命令提示符打开。然后,你可以直接运行控制台应用程序。

  1. Keep an administrative command prompt open. Then you can just run the console app directly.

(如你所说)VS运行作为管理员。调试您的应用程序,只有当这是绝对必要的。

(As you suggested) run VS as admin. This is absolutely necessary only when debugging your app.

创建应用程序manifiest文件,指定requestedExecutionLevel水平=requireAdministrator。见如何强制我的。 NET应用程序以管理员身份运行在Windows 7?了解更多详情。

Create an application manifiest file, specifying requestedExecutionLevel level="requireAdministrator". See How to force my .NET App to run as administrator on Windows 7? for more details.

这篇关于System.ServiceModel.AddressAccessDeniedException:HTTP不能注册网址HTTP :: 8080的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆