c# – System.ServiceModel.AddressAccessDeniedException:HTTP无法注册URL http :: 8080

栏目: C# · 发布时间: 5年前

内容简介:http://stackoverflow.com/questions/22686469/system-servicemodel-addressaccessdeniedexception-http-could-not-register-url-ht

我创建了我的第一个自主的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”.详见 How to force my .NET App to run as administrator on Windows 7? .

http://stackoverflow.com/questions/22686469/system-servicemodel-addressaccessdeniedexception-http-could-not-register-url-ht


以上就是本文的全部内容,希望本文的内容对大家的学习或者工作能带来一定的帮助,也希望大家多多支持 码农网

查看所有标签

猜你喜欢:

本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们

The  C Programming Language

The C Programming Language

Brian W. Kernighan、Dennis M. Ritchie / Prentice Hall / 1988-4-1 / USD 67.00

Presents a complete guide to ANSI standard C language programming. Written by the developers of C, this new version helps readers keep up with the finalized ANSI standard for C while showing how to ta......一起来看看 《The C Programming Language》 这本书的介绍吧!

HTML 压缩/解压工具
HTML 压缩/解压工具

在线压缩/解压 HTML 代码

MD5 加密
MD5 加密

MD5 加密工具

UNIX 时间戳转换
UNIX 时间戳转换

UNIX 时间戳转换