0

I have created a test service with the WCF template of Visual Studio 2017. It creates a library project with this app config file:

<?xml version="1.0" encoding="utf-8" ?>
<configuration>

  <appSettings>
    <add key="aspnet:UseTaskFriendlySynchronizationContext" value="true" />
  </appSettings>
  <system.web>
    <compilation debug="true" />
  </system.web>
  <!-- Al implementar el proyecto de la biblioteca de servicios, el contenido del archivo de configuración se debe agregar al archivo 
  app.config del host. La configuración del sistema no admite archivos de configuración en las bibliotecas. -->
  <system.serviceModel>
    <services>
      <service name="Dummy.Service1">
        <host>
          <baseAddresses>
            <add baseAddress = "http://localhost:8733/Design_Time_Addresses/Dummy/Service1/" />
          </baseAddresses>
        </host>
        <!-- Service Endpoints -->
        <!-- A menos que esté completa, la dirección está en relación con la dirección base suministrada anteriormente -->
        <endpoint address="" binding="basicHttpBinding" contract="Dummy.IService1">
          <!-- 
              Antes de la implementación, se debe quitar o reemplazar el siguiente elemento de identidad para reflejar la 
              identidad bajo la que funciona el servicio implementado. Si se quita, WCF deducirá automáticamente una identidad 
               apropiada.
          -->
          <identity>
            <dns value="localhost"/>
          </identity>
        </endpoint>
        <!-- Metadata Endpoints -->
        <!-- El servicio utiliza el extremo de intercambio de metadatos para describirse a sí mismo ante los clientes. --> 
        <!-- Este extremo no utiliza un enlace seguro, por lo que se debe proteger o quitar antes de la implementación -->
        <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"/>
      </service>
    </services>
    <behaviors>
      <serviceBehaviors>
        <behavior>
          <!-- Para evitar revelar información de los metadatos, 
          establezca los valores siguientes en false antes de la implementación -->
          <serviceMetadata httpGetEnabled="True" httpsGetEnabled="True"/>
          <!-- Para recibir detalles de las excepciones en los fallos, con el fin de poder realizar la depuración, 
          establezca el valor siguiente en true. Para no revelar información sobre las excepciones 
          establézcalo en false antes de la implementación -->
          <serviceDebug includeExceptionDetailInFaults="False" />
        </behavior>
      </serviceBehaviors>
    </behaviors>
  </system.serviceModel>

</configuration>

Then I use the same app config file in my service, changing the needed information. The app config file is this:

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
    <startup> 
        <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.7.2" />
    </startup>




  <!--WCF-->
  <appSettings>
    <add key="aspnet:UseTaskFriendlySynchronizationContext" value="true" />
  </appSettings>
  <system.web>
    <compilation debug="true" />
  </system.web>
  <!-- Al implementar el proyecto de la biblioteca de servicios, el contenido del archivo de configuración se debe agregar al archivo 
  app.config del host. La configuración del sistema no admite archivos de configuración en las bibliotecas. -->
  <system.serviceModel>
    <services>
      <service name="GestorAplicaciones.Wcf.Servicio.Net.GestorAplicacionesService">
        <host>
          <baseAddresses>
            <add baseAddress = "http://localhost:8733/GestorAplicaciones" />
          </baseAddresses>
        </host>
        <!-- Service Endpoints -->
        <!-- A menos que esté completa, la dirección está en relación con la dirección base suministrada anteriormente -->
        <endpoint address="" binding="basicHttpBinding" contract="GestorAplicaciones.Wcf.Comun.Net.IGestorAplicacionesService">
          <!-- 
              Antes de la implementación, se debe quitar o reemplazar el siguiente elemento de identidad para reflejar la 
              identidad bajo la que funciona el servicio implementado. Si se quita, WCF deducirá automáticamente una identidad 
               apropiada.
          -->
          <identity>
            <dns value="localhost"/>
          </identity>
        </endpoint>
        <!-- Metadata Endpoints -->
        <!-- El servicio utiliza el extremo de intercambio de metadatos para describirse a sí mismo ante los clientes. -->
        <!-- Este extremo no utiliza un enlace seguro, por lo que se debe proteger o quitar antes de la implementación -->
        <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
      </service>
    </services>
    <behaviors>
      <serviceBehaviors>
        <behavior>
          <!-- Para evitar revelar información de los metadatos, 
          establezca los valores siguientes en false antes de la implementación -->
          <serviceMetadata httpGetEnabled="True" httpsGetEnabled="True"/>
          <!-- Para recibir detalles de las excepciones en los fallos, con el fin de poder realizar la depuración, 
          establezca el valor siguiente en true. Para no revelar información sobre las excepciones 
          establézcalo en false antes de la implementación -->
          <serviceDebug includeExceptionDetailInFaults="False" />
        </behavior>
      </serviceBehaviors>
    </behaviors>
  </system.serviceModel>
  <!--FIN WCF-->
</configuration>

Finally I have a WPF application to host the service. The code, in code behind, is this:

public partial class MainWindow : Window
    {
        public MainWindow()
        {
            InitializeComponent();


            using (_host = new ServiceHost(typeof(GestorAplicacionesService)))
            {
                _host.Open();
            }
        }



        private ServiceHost _host;
    }

When I run the WPF application, I get the error that I can't register the URL.

I have find some solutions in this thread, HTTP could not register URL http://+:8000/HelloWCF/. Your process does not have access rights to this namespace

In sumary, one solution it is to run visual studio with admin priviliges, and another solution it is to set the URL with netsh, but I would like if really I need to do that, because if the Dummy project created with the WCF template doens't need to do that, because the service is created.

Perhaps, like the Dummy project it is a library porject, when I run in visual studio, visual studio creates a custom enviroment and then it can be run, but I would like to know if really in my project I can solve this problem without use netsh or run with admin privileges.

Thanks.

1
  • using statement will release the service host object and would not host the service correctly. besides, you must at least choose one to enable the port via corresponding privileges. Commented Feb 11, 2019 at 10:02

1 Answer 1

1

On debugging you app in visual studio right click on Visual Studio > Run as Administrator > Open your project and run the service. This is a privilege related issue.

And also in target machine use netsh add urlacl cmd :

netsh add urlacl url=http://+:8000/HelloWCF/ user=DOMAIN\user

I hope to be useful !

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.