title: Simple WCF Service Error while Executing
body: <p>This may be very basic question in WCF. I'm new to it and not sure how to solve this please.</p>
  
  <p>I have taken the WCF Service application template from visual studio and here is the code below what i have</p>
  
  <p>**Interface: IService1.cs **</p>
  
  <pre><code>using System.ServiceModel;
  namespace WcfService1
  {
      [ServiceContract]
      public interface IService1
      {
          [OperationContract]
          string GetData(int value);
      }
  }
  </code></pre>
  
  <p>** Service File Name : Service1.svc **</p>
  
  <pre><code>using System.ServiceModel;
  namespace WcfService1
  {
      public class Service1 : IService1
      {
          public string GetData(int value)
          {
              return string.Format("You entered: {0}", value);
          }
      }
  }
  </code></pre>
  
  <p>and i have edited the web.config file as </p>
  
  <pre><code>&lt;?xml version="1.0"?&gt;
  &lt;configuration&gt;
    &lt;system.serviceModel&gt;
      &lt;behaviors&gt;
        &lt;serviceBehaviors&gt;
          &lt;behavior name="mexBehaviour"&gt;
            &lt;serviceMetadata httpGetEnabled="True"/&gt;
          &lt;/behavior&gt;
        &lt;/serviceBehaviors&gt;
      &lt;/behaviors&gt;
      &lt;services&gt;
        &lt;service behaviorConfiguration="mexBehaviour" name="WcfService1.IService1"&gt;
          &lt;endpoint address="Service1" binding="basicHttpBinding" contract="WcfService1.IService1"/&gt;
          &lt;host&gt;
            &lt;baseAddresses&gt;
              &lt;add baseAddress="http://localhost:8080/"/&gt;
            &lt;/baseAddresses&gt;
          &lt;/host&gt;
        &lt;/service&gt;
      &lt;/services&gt;
    &lt;/system.serviceModel&gt;
    &lt;system.web&gt;
      &lt;compilation debug="true"/&gt;
    &lt;/system.web&gt;
  &lt;/configuration&gt;
  </code></pre>
  
  <p><strong>and the Error i get is:</strong>
  Failed to add a service. Service metadata may not be accessible. Make sure your service is running and exposing metadata.</p>
  
  <p><strong>in Detail:</strong></p>
  
  <pre><code>Error: Cannot obtain Metadata from http://localhost:59790/Service1.svc If this is a Windows (R) Communication Foundation service to which you have access, please check that you have enabled metadata publishing at the specified address.  For help enabling metadata publishing, please refer to the MSDN documentation at http://go.microsoft.com/fwlink/?LinkId=65455.WS-Metadata Exchange Error    URI: http://localhost:59790/Service1.svc    Metadata contains a reference that cannot be resolved: 'http://localhost:59790/Service1.svc'.    Content Type application/soap+xml; charset=utf-8 was not supported by service http://localhost:59790/Service1.svc.  The client and service bindings may be mismatched.    The remote server returned an error: (415) Unsupported Media Type.HTTP GET Error    URI: http://localhost:59790/Service1.svc    The HTML document does not contain Web service discovery information.
  </code></pre>
  
  <p>Original Webconfig file as generated by Visual Studio</p>
  
  <pre><code>&lt;?xml version="1.0"?&gt;
  &lt;configuration&gt;
    &lt;system.web&gt;
      &lt;compilation debug="true" targetFramework="4.0" /&gt;
    &lt;/system.web&gt;
    &lt;system.serviceModel&gt;
      &lt;behaviors&gt;
        &lt;serviceBehaviors&gt;
          &lt;behavior&gt;
            &lt;serviceMetadata httpGetEnabled="true"/&gt;
            &lt;serviceDebug includeExceptionDetailInFaults="false"/&gt;
          &lt;/behavior&gt;
        &lt;/serviceBehaviors&gt;
      &lt;/behaviors&gt;
      &lt;serviceHostingEnvironment multipleSiteBindingsEnabled="true" /&gt;
    &lt;/system.serviceModel&gt;
   &lt;system.webServer&gt;
      &lt;modules runAllManagedModulesForAllRequests="true"/&gt;
    &lt;/system.webServer&gt;  
  &lt;/configuration&gt;
  </code></pre>
  
  <p>I am sure this got to be simple configuration file problem. Not sure how to figure it out.
  Thanks for your help in advance.</p>
  
  <p><strong>Modifications to Web.config to add netTcpBinding Binding, which throws error in WCF testClient:</strong></p>
  
  <pre><code>&lt;?xml version="1.0"?&gt;
  &lt;configuration&gt;
    &lt;appSettings&gt;
      &lt;add key="aspnet:UseTaskFriendlySynchronizationContext" value="true" /&gt;
    &lt;/appSettings&gt;
    &lt;system.web&gt;
      &lt;compilation debug="true" targetFramework="4.0" /&gt;
    &lt;/system.web&gt;
    &lt;system.serviceModel&gt;
      &lt;behaviors&gt;
        &lt;serviceBehaviors&gt;
          &lt;behavior name="mexBehaviour"&gt;
            &lt;serviceMetadata httpGetEnabled="True"/&gt;
          &lt;/behavior&gt;
        &lt;/serviceBehaviors&gt;
      &lt;/behaviors&gt;
      &lt;services&gt;
        &lt;service behaviorConfiguration="mexBehaviour" name="WcfService1.Service1"&gt;
          &lt;endpoint address="Service1" binding="basicHttpBinding" contract="WcfService1.IService1"/&gt;
          &lt;endpoint address="Service1" binding="netTcpBinding" contract="WcfService1.IService1"/&gt;
          &lt;endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"/&gt;
          &lt;host&gt;
            &lt;baseAddresses&gt;
              &lt;add baseAddress="http://localhost:8080/"/&gt;
              &lt;add baseAddress="net.tcp://localhost:8090/"/&gt;
            &lt;/baseAddresses&gt;
          &lt;/host&gt;
        &lt;/service&gt;
      &lt;/services&gt;
    &lt;/system.serviceModel&gt;
    &lt;system.webServer&gt;
      &lt;modules runAllManagedModulesForAllRequests="true"/&gt;
      &lt;directoryBrowse enabled="true"/&gt;
    &lt;/system.webServer&gt;
  &lt;/configuration&gt;&lt;br&gt;------------------------------------------------------------------
  </code></pre>
  
  <p><br></p>
  
  <p><strong>Project 2 : BasicHttp and NetTcp Binding hosted in Console App</strong></p>
  
  <p>I have the below web.config file(Just copied again, so that we can have all under one glance)</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8" ?&gt;
  &lt;configuration&gt;
    &lt;system.serviceModel&gt;
      &lt;services&gt;
        &lt;service name="HelloService.HelloService"  behaviorConfiguration="mexBehaviour"&gt;
          &lt;endpoint address="HelloService" binding="basicHttpBinding" contract="HelloService.IHelloService"&gt;&lt;/endpoint&gt;
          &lt;endpoint address="HelloService" binding="netTcpBinding" contract="HelloService.IHelloService"&gt;&lt;/endpoint&gt;
          &lt;endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"&gt;&lt;/endpoint&gt;
          &lt;host&gt;
            &lt;baseAddresses&gt;
              &lt;add baseAddress="http://localhost:59084/"/&gt;
              &lt;add baseAddress="net.tcp://localhost:59076/"/&gt;
            &lt;/baseAddresses&gt;
          &lt;/host&gt;
        &lt;/service&gt;
      &lt;/services&gt;
      &lt;behaviors&gt;
        &lt;serviceBehaviors&gt;
          &lt;behavior name="mexBehaviour"&gt;
            &lt;serviceMetadata httpGetEnabled="True"/&gt;
          &lt;/behavior&gt;
        &lt;/serviceBehaviors&gt;
      &lt;/behaviors&gt;
    &lt;/system.serviceModel&gt;
  &lt;/configuration&gt;
  </code></pre>
  
  <p>and Console App code for hosting</p>
  
  <pre><code>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();
              }
          }
      }
  }
  </code></pre>
  
  <p><strong>Error :</strong>  I'm getting error at host.Open() method where it says,</p>
  
  <pre><code> 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).
  </code></pre>
  
  <ul>
  <li>I tried other port number like 53895, thinking port 8080 might be pre
  occupied. No Luck!! </li>
  <li>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?</li>
  <li>Also, any suggestions to make this
  work would be appriciated.  May be something to do with Webconfig
  again??</li>
  </ul>
  
  <p>Class that extends Interface</p>
  
  <pre><code>using System.ServiceModel;
  namespace HelloService
  {
      public class HelloService : IHelloService
      {
          public string GetMessage(string Name)
          {
              return "Hello " + Name;
          }
      }
  }
  </code></pre>
  
  <p>Interface :</p>
  
  <pre><code>namespace HelloService
  {
      [ServiceContract]
      public interface IHelloService
      {
          [OperationContract]
          String GetMessage(String Name);
      }
  }
  </code></pre>
  
  <p>Thanks in advance!!</p>