Click here to Skip to main content
15,891,513 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am using an windows service to host the WCF Pooling Duplex Service, whenever wcf service enters the faulted state I want to restart the WCF Duplex Service. - Restart of normal WCF Service works fine but when I try to restart the WCF Duplex Service it throws an following exception.

C#
The ChannelDispatcher at 'http://localhost:8731/TestService' with contract(s) 
"ITestService"' is unable to open its IChannelListener.


This is the inner exception and its stack trace

Innerexception

C#
**A registration already exists for URI 'http://localhost:8731/TestService'.**


StackTrace

C#
at System.ServiceModel.Channels.UriPrefixTable`1.RegisterUri(Uri uri, HostNameComparisonMode hostNameComparisonMode, TItem item)
at System.ServiceModel.Channels.HttpTransportManager.Register(TransportChannelListener channelListener)
at System.ServiceModel.Channels.TransportManager.Open(TransportChannelListener channelListener)
at System.ServiceModel.Channels.TransportManagerContainer.Open(SelectTransportManagersCallback selectTransportManagerCallback)
at System.ServiceModel.Channels.TransportChannelListener.OnOpen(TimeSpan timeout)
at System.ServiceModel.Channels.HttpChannelListener`1.OnOpen(TimeSpan timeout)
at System.ServiceModel.Channels.CommunicationObject.Open(TimeSpan timeout)
at System.ServiceModel.Channels.PollingDuplexChannelListener.OnOpen(TimeSpan timeout)
at System.ServiceModel.Channels.CommunicationObject.Open(TimeSpan timeout)
at System.ServiceModel.Dispatcher.ChannelDispatcher.OnOpen(TimeSpan timeout)



I tried to create a small sample code which is as follows.

C#
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Diagnostics;
using System.Linq;
using System.ServiceModel;
using System.ServiceProcess;
using System.Text;
using System.Threading.Tasks;

namespace WindowsHostedWcfService
{
    public partial class Service1 : ServiceBase
    {
        public Service1()
        {
            InitializeComponent();
        }

        protected override void OnStart(string[] args)
        {

            try
            {
                // Creating the Service Host object for service "TestService"
                ServiceHost TestService = new ServiceHost(typeof(TestService));
                // Openiong the Service
                TestService.Open();
                TestService.Faulted += TestService_Faulted;

                // Closing the service and wait for the service to close
                AsyncCallback AsyncCallback = new System.AsyncCallback(CloseCompleted);
                TestService.BeginClose(AsyncCallback, null);
            }
            catch (Exception Ex)
            {

            }
        }

        private void CloseCompleted(IAsyncResult i)
        {
            // Creating the new service host object .
            TestService ts = new TestService();
            ServiceHost TestService1 = new ServiceHost(ts);

            // When try to reoprn the service it throws the exception here ,
            TestService1.Open();
            TestService1.Faulted += TestService_Faulted;
        }

        void TestService_Faulted(object sender, EventArgs e)
        {

        }

        protected override void OnStop()
        {

        }

        public void Run()
        {
            OnStart(new string[] { });
        }
    }


    // Service implementing the Duplex Contract 
    [ServiceBehavior(ConcurrencyMode = ConcurrencyMode.Single, InstanceContextMode = InstanceContextMode.Single)]
    public class TestService : ITestService
    {
        public TestService()
        {

        }

        public void TestMethod()
        {
            throw new Exception();
        }
    }


    // A Simple duplex WCf Service with the call back contract of type ICallBack
    [ServiceContract(CallbackContract = typeof(ICallBack))]
    public interface ITestService
    {
        [OperationContract]
        void TestMethod();
    }

    // Callback COntract
    [ServiceContract]
    public interface ICallBack
    {
        // Operatin contract with oneway property set to True
        [OperationContract(IsOneWay = true)]
        void TestCallbackMethod();
    }
}

So because of this every time the WCf service goes into the faulted state I have to restart my windows service so that WCF service starts running,

thanks!
Posted
Comments
Dominic Burford 10-Nov-14 9:13am    
*A registration already exists for URI 'http://localhost:8731/TestService'.**

That error usually indicates that you have more than one service using the same endpoint. Check what endpoints your services are using.
Nirav Savla 13-Nov-14 0:51am    
Hi ,
Actually, I am using the PollingDuplexBinding , generally with the normal binding if I stop or abort the service and then I restart the service it works successfully but with the PollingDuplexBinding when I tries to restart my service it gives me that error.

Thanks

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900