The process does not have access rights to this namespace

0

I am making a personalized WCF encoder following the guidelines of this site using-mtom

I create a web Service by taking a file.zip

    public class Service1 : IService1
{
    public FileResponse GetData(string value)
    {
        FileResponse response = new FileResponse
        {
            Filename = "Archivo de Prueba",
            Contents = File.ReadAllBytes(@"C:\temp2A25FEEFBA.zip")
        };

        return response;
    }
}

class projects are like this:

  • ++ CnsTestService console where I run the ws

  • ++ ServiceTest service

  • ++ TextAndMtom classes to perform the Mtom and Inspector encoder

  • ++ IISHost where I host the WS

  • In the console (CnsTestService) I have the following lines:

        class Program
    {
        static void Main(string[] args)
        {
    
            string baseAddress = "http://localhost:62859/Service1.svc";
            ServiceHost host = new ServiceHost(typeof(Service1), new Uri(baseAddress));
            host.Description.Behaviors.Add(new ServiceMetadataBehavior { HttpGetEnabled = true });
            host.AddServiceEndpoint(typeof(IMetadataExchange), MetadataExchangeBindings.CreateMexHttpBinding(), "mex");
            CustomBinding binding = new CustomBinding(
                new TextOrMtomEncodingBindingElement(),
                new HttpTransportBindingElement());
            CustomBinding mtomBinding = new CustomBinding(new MtomMessageEncodingBindingElement(), new HttpTransportBindingElement());
            host.AddServiceEndpoint(typeof(IService1), binding, "").Behaviors.Add(new IncomingEncoderInspector());
            host.AddServiceEndpoint(typeof(IService1), mtomBinding, "mtom");
            host.Open();
            Console.WriteLine("Host opened");
    
            for (int i = 0; i < 3; i++)
            {
                MessageEncodingBindingElement mebe;
                string address;
                switch (i)
                {
                    case 0:
                        mebe = new MtomMessageEncodingBindingElement();
                        address = baseAddress + "/mtom";
                        Console.WriteLine("Using MTOM to MTOM-only endpoint");
                        break;
                    case 1:
                        mebe = new MtomMessageEncodingBindingElement();
                        address = baseAddress;
                        Console.WriteLine("Using MTOM to TextAndMtom endpoint");
                        break;
                    default:
                        mebe = new TextMessageEncodingBindingElement();
                        address = baseAddress;
                        Console.WriteLine("Using TEXT to TextAndMtom endpoint");
                        break;
                }
    
                CustomBinding clientBinding = new CustomBinding(mebe, new HttpTransportBindingElement());
                ChannelFactory<IService1> factory = new ChannelFactory<IService1>(clientBinding, new EndpointAddress(address));
                IService1 proxy = factory.CreateChannel();
                try
                {
                    Console.WriteLine(proxy.GetData("foo.bar"));
                }
                catch (Exception e)
                {
                    Console.WriteLine(e);
                }
    
                ((IClientChannel)proxy).Close();
                factory.Close();
            }
    
            Console.WriteLine("Press ENTER to close");
            Console.ReadLine();
            host.Close();
        }
    }
    

    in the Service1.svc code is this way.

    the error or warning in the console is in the line host.Open ();

    Message = HTTP could not register the URL link .  The process does not have access rights to this namespace (See link for more information).   //~/App_Code/Service.cs C: \ Users \ emiliog \ source \ repos \ TextAndMtom \ ServiceTest \ Service1.cs

    WHAT can be the Problem ??

        
    asked by ger 02.11.2018 в 23:05
    source

    1 answer

    1

    the answer was to run the netsh as the link says

    netsh http add urlacl url=http://+:80/ user=Everyone
    

    but on the line:

    http://localhost:62859/Service1.svc
    

    change to listen to the port localhost: 80

        
    answered by 06.11.2018 / 14:17
    source