Ramu
Ramu

Reputation: 353

WCF Service in Console app throwing error

BasicHttp and NetTcp Binding hosted in Console App

I have the below web.config file

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

The Interface

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

Class that extends Interface

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

and Console App code for hosting

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

I am getting below error when i try to run the Console app

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).

Thanks for your help in advance!!

Upvotes: 0

Views: 540

Answers (1)

Aditya Patil
Aditya Patil

Reputation: 558

Your code looks alright. I tried it and it works. Try the solution here: HTTP could not register URL http://+:8000/HelloWCF/. Your process does not have access rights to this namespace

It basically tells you to close your Visual Studio IDE and open it by doing a right-click "Run as administrator"

Upvotes: 1

Related Questions