控制台应用程序中的WCF服务抛出错误

时间:2014-06-11 12:05:53

标签: wcf binding console-application wcf-hosting

在Console App中托管的BasicHttp和NetTcp绑定

我有以下web.config文件

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
  <system.serviceModel>
    <services>
      <service name="HelloService.HelloService"  behaviorConfiguration="mexBehaviour">
        <endpoint address="HelloService" binding="basicHttpBinding" contract="HelloService.IHelloService"></endpoint>
        <endpoint address="HelloService" binding="netTcpBinding" contract="HelloService.IHelloService"></endpoint>
        <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"></endpoint>
        <host>
          <baseAddresses>
            <add baseAddress="http://localhost:59084/"/>
            <add baseAddress="net.tcp://localhost:59076/"/>
          </baseAddresses>
        </host>
      </service>
    </services>
    <behaviors>
      <serviceBehaviors>
        <behavior name="mexBehaviour">
          <serviceMetadata httpGetEnabled="True"/>
        </behavior>
      </serviceBehaviors>
    </behaviors>
  </system.serviceModel>
</configuration>

界面

namespace HelloService
{
    [ServiceContract]
    public interface IHelloService
    {
        [OperationContract]
        String GetMessage(String Name);
    }
}

扩展接口

的类
 using System.ServiceModel;
    namespace HelloService
    {
        public class HelloService : IHelloService
        {
            public string GetMessage(string Name)
            {
                return "Hello " + Name;
            }
        }
    }

和用于托管的控制台应用代码

using System.ServiceModel;

namespace HelloServiceHost
{
    class Program
    {
        static void Main()
        {
            using(ServiceHost host  = new ServiceHost(typeof(HelloService.HelloService)))
            {
                host.Open();
                Console.WriteLine("Host Started");
                Console.ReadLine();
            }
        }
    }
}

当我尝试运行控制台应用时,我收到以下错误

HTTP could not register URL http://+:8080/. Your process does not have
access rights to this namespace (see
http://go.microsoft.com/fwlink/?LinkId=70353 for details).
  • 我尝试了其他端口号53895,认为端口8080可能已被占用。没运气!!
  • 当我浏览此错误时,由于我的原因,我开始知道这个问题 帐户不是管理员。现在我的疑问是WCFTest客户端也被执行了 在我的帐户本身。它如何运行类似的代码,我不能?

    此外,任何提出这项工作的建议都会受到关注。也许 又与Webconfig有关吗??

提前感谢您的帮助!!

1 个答案:

答案 0 :(得分:1)

您的代码看起来不错。我尝试了它,它的工作原理。 请尝试此处的解决方案:HTTP could not register URL http://+:8000/HelloWCF/. Your process does not have access rights to this namespace

它基本上告诉您关闭Visual Studio IDE并通过右键单击打开它&#34;以管理员身份运行&#34;

相关问题