0

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).
  • I tried other port number like 53895, thinking port 8080 might be pre occupied. No Luck!!
  • When i browsed for this error, i came to know this problem due to my account being non admin. Now my doubt is WCFTest Client also execued under my account itself. How can it run the similar code and i can't?

    Also, any suggestions to make this work would be appriciated. May be something to do with Webconfig again??

Thanks for your help in advance!!

Ramu
  • 343
  • 1
  • 6
  • 21

1 Answers1

1

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"

Community
  • 1
  • 1
Aditya Patil
  • 548
  • 4
  • 14
  • i cannot run VS IDE in admin mode, i dont have the admin rights. Ihave accepted the answer, just looking if i can get any work around for the same. Thank you mate – Ramu Jun 17 '14 at 14:05
  • @Ramu, sorry that you are still having the problem. If you can prove it to them that this is causing you the issue, they may ease of on the admin rights. – Aditya Patil Jun 17 '14 at 15:07
  • Yeah make sense mate. i was just testing the app. Actually i need to host it in IIS. just testing around byu hosting it in console app. Thank you :) – Ramu Jun 17 '14 at 15:42