简体   繁体   中英

C# WCF self-hosting opened but refused by browsers

I've a WCF self-hosted inside a Windows Service which runs as Local System. WCF configuration is done programmaticaly (means without app.config configuration).

This WCF service host is opened correctly whithout any exceptions and I can see 2 final endpoints in debug mode (main endpoint and mex endpoint for metadata).

When I open web browser (IE) to my main endpoint " https://myserver.mydomain.fr:443/endpoint " , I get error "This page can't be displayed". If I run a IE network diagnostic, I got: "This driver or remote ressource is not configured to accept connections on port https"

Url has been reserved with netsh http add urlacl url= https://myserver.mydomain.fr:443/endpoint/ and certificate has been attached to port 443 correctly (with GUID of this Windows Service and certificate thumbprint).

Do you know where I shoud focus my effort? On WCF configuration? It worked but stop working some days ago...

UPDATE1 : Here is my code.

My main ServiceHost class is:

public class CustomServiceHost : ServiceHost
{
    private string _AssembyIDOfWindowsService=String.Empty;
    private string _mainEndPointRelativeAddress = String.Empty;
    private string _mexRelativeAddress = "mex";

    public CustomServiceHost(Type serviceType, Uri[] baseAddresses, string mainEndPointRelativeAddress, string mexRelativeAddress)
    : base(serviceType, baseAddresses)
    {
        _mainEndPointRelativeAddress = mainEndPointRelativeAddress;
        _mexRelativeAddress = mexRelativeAddress;
    }

    protected override void InitializeRuntime()
    {
        //Add Service debug behavior
        AddServiceDebugBehavior();

        //Add main endpoint and mex endpoint
        AddEndpoints();

        //Configure throttling: means number max of connections, sessions and objects
        ConfigureThrottling();

        //Allow clients to connect without client certificates
        Credentials.ClientCertificate.Authentication.RevocationMode = System.Security.Cryptography.X509Certificates.X509RevocationMode.NoCheck;

            Base.InitializeRuntime(); //My error was here... WTF... So easy...
    }

    /// <summary>
    /// Add main endpoint on wer server and mex endpoint for operations signatures
    /// </summary>
    private void AddEndpoints()
    {
        BasicHttpsBinding basicHttpsBinding = WcfHelpers.ConfigureBasicHttpsBinding();

        foreach (Uri address in this.BaseAddresses)
        {
            //Create endpoint with or without an endpoint name (ie https://myserver.mydomain.fr/443 or https://myserver.mydomain.fr/443/endpoint )
            ServiceEndpoint endpoint = new ServiceEndpoint(
                ContractDescription.GetContract(Description.ServiceType),
                basicHttpsBinding,
                new EndpointAddress(address + _mainEndPointRelativeAddress));

            //Add main service endpoint to service
            AddServiceEndpoint(endpoint);

            //adding behavior
            AddServiceMetadataBehavior();

            //adding mex endpoint (address.AbsoluteUri always finish with \ so not needed between base address and mexRelativeEndpoint
            AddServiceEndpoint(
                ServiceMetadataBehavior.MexContractName,
                MetadataExchangeBindings.CreateMexHttpsBinding(),
                address.AbsoluteUri + _mexRelativeAddress);
        }
    }

    /// <summary>
    /// Add debug behavior if not already done
    /// </summary>
    private void AddServiceDebugBehavior()
    {
        ServiceDebugBehavior debugBehavior = Description.Behaviors.Find<ServiceDebugBehavior>();

        if (debugBehavior == null)
        {
            Description.Behaviors.Add(
                new ServiceDebugBehavior() { IncludeExceptionDetailInFaults = true });
        }
        else
        {
            if (!debugBehavior.IncludeExceptionDetailInFaults)
                debugBehavior.IncludeExceptionDetailInFaults = true;
        }
    }

    /// <summary>
    /// Add service metadata behavior
    /// </summary>
    private void AddServiceMetadataBehavior()
    {
        ServiceMetadataBehavior metadataBehavior = Description.Behaviors.Find<ServiceMetadataBehavior>();

        if (metadataBehavior == null)
        {
            ServiceMetadataBehavior serviceMetadataBehavior = new ServiceMetadataBehavior();
            serviceMetadataBehavior.HttpsGetEnabled = true;
            Description.Behaviors.Add(serviceMetadataBehavior);
        }
    }

    /// <summary>
    /// Configure max numbers of concurrent accesses (calls, instances and sessions)
    /// </summary>
    private void ConfigureThrottling()
    {
        ServiceThrottlingBehavior throttleBehavior = Description.Behaviors.Find<ServiceThrottlingBehavior>();

        if (throttleBehavior != null) return;

        throttleBehavior = new ServiceThrottlingBehavior
        {
            MaxConcurrentCalls = 100, // MaxConcurrentCalls should be set to less than the SQL connection pool size in queued scenarios
            MaxConcurrentInstances = 100,
            MaxConcurrentSessions = 100
        };

        Description.Behaviors.Add(throttleBehavior);
    }
}

To configure httpsbinding, I use this one:

/// <summary>
/// Used by server and clients to define common bindings (thats why its a static method)
/// </summary>
public class WcfHelpers
{
    public static BasicHttpsBinding ConfigureBasicHttpsBinding()
    {
        BasicHttpsBinding basicHttpsBinding;

        basicHttpsBinding = new BasicHttpsBinding
        {
            Name = "myBasicHttpsBinding",

            OpenTimeout = new TimeSpan(0, 10, 0),
            CloseTimeout = new TimeSpan(0, 10, 0),
            SendTimeout = new TimeSpan(0, 10, 0),
            MaxBufferPoolSize = 104857600,
            MaxReceivedMessageSize = 104857600,
            Namespace = "https://myserver.mydomain.fr/443/endpoint",
            ReaderQuotas = new XmlDictionaryReaderQuotas()
            {
                MaxDepth = 104857600,
                MaxStringContentLength = 104857600,
                MaxArrayLength = 104857600,
                MaxBytesPerRead = 104857600,
                MaxNameTableCharCount = 104857600
            },
            Security =
            {
                Mode = BasicHttpsSecurityMode.Transport
            }
        };
        return basicHttpsBinding;
    }
}

An finally I create my ServiceHost like this:

//Create my ServiceHost
CustomServiceHost _serviceHost = new CustomServiceHost(typeof(WCF_Service_Library.Service)
                        , new Uri[] { new Uri("https://myserver.mydomain.fr:443/") }
                        , "endpoint"
                        , "mex");

//Attach a selected X509 certificate (X509Certificate2 certFound)
_serviceHost.Credentials.ServiceCertificate.Certificate = certFound;

//Open ServiceHost
_serviceHost.Open();

...

//Close ServiceHost
_serviceHost.Close();

UPDATE2 : WCF log file is:

<events><E2ETraceEvent xmlns="http://schemas.microsoft.com/2004/06/E2ETraceEvent"><System xmlns="http://schemas.microsoft.com/2004/06/windows/eventlog/system"><EventID>0</EventID><Type>3</Type><SubType Name="Transfer">0</SubType><Level>255</Level><TimeCreated SystemTime="2016-07-19T09:55:54.1825288Z" /><Source Name="System.ServiceModel" /><Correlation ActivityID="{00000000-0000-0000-0000-000000000000}" RelatedActivityID="{de1073e0-a063-4b78-a802-e2ea11c2711d}" /><Execution ProcessName="Windows Service" ProcessID="6676" ThreadID="4" /><Channel/><Computer>DEV01</Computer></System><ApplicationData></ApplicationData></E2ETraceEvent><E2ETraceEvent xmlns="http://schemas.microsoft.com/2004/06/E2ETraceEvent"><System xmlns="http://schemas.microsoft.com/2004/06/windows/eventlog/system"><EventID>131085</EventID><Type>3</Type><SubType Name="Start">0</SubType><Level>255</Level><TimeCreated SystemTime="2016-07-19T09:55:54.1985712Z" /><Source Name="System.ServiceModel" /><Correlation ActivityID="{de1073e0-a063-4b78-a802-e2ea11c2711d}" /><Execution ProcessName="Windows Service" ProcessID="6676" ThreadID="4" /><Channel/><Computer>DEV01</Computer></System><ApplicationData><TraceData><DataItem><TraceRecord xmlns="http://schemas.microsoft.com/2004/10/E2ETraceEvent/TraceRecord" Severity="Start"><TraceIdentifier>http://msdn.microsoft.com/fr-FR/library/System.ServiceModel.Diagnostics.ActivityBoundary.aspx</TraceIdentifier><Description>Limite d'activité.</Description><AppDomain>Windows Service</AppDomain><ExtendedData xmlns="http://schemas.microsoft.com/2006/08/ServiceModel/DictionaryTraceRecord"><ActivityName>Construire ServiceHost 'WCF_Service_Library.Service'.</ActivityName><ActivityType>Construct</ActivityType></ExtendedData></TraceRecord></DataItem></TraceData></ApplicationData></E2ETraceEvent><E2ETraceEvent xmlns="http://schemas.microsoft.com/2004/06/E2ETraceEvent"><System xmlns="http://schemas.microsoft.com/2004/06/windows/eventlog/system"><EventID>524326</EventID><Type>3</Type><SubType Name="Information">0</SubType><Level>8</Level><TimeCreated SystemTime="2016-07-19T09:55:54.1985712Z" /><Source Name="System.ServiceModel" /><Correlation ActivityID="{de1073e0-a063-4b78-a802-e2ea11c2711d}" /><Execution ProcessName="Windows Service" ProcessID="6676" ThreadID="4" /><Channel/><Computer>DEV01</Computer></System><ApplicationData><TraceData><DataItem><TraceRecord xmlns="http://schemas.microsoft.com/2004/10/E2ETraceEvent/TraceRecord" Severity="Information"><TraceIdentifier>http://msdn.microsoft.com/fr-FR/library/System.ServiceModel.GetServiceElement.aspx</TraceIdentifier><Description>Obtenir ServiceElement.</Description><AppDomain>Windows Service</AppDomain><ExtendedData xmlns="http://schemas.microsoft.com/2006/08/ServiceModel/ServiceConfigurationTraceRecord"><FoundServiceElement>False</FoundServiceElement></ExtendedData></TraceRecord></DataItem></TraceData></ApplicationData></E2ETraceEvent><E2ETraceEvent xmlns="http://schemas.microsoft.com/2004/06/E2ETraceEvent"><System xmlns="http://schemas.microsoft.com/2004/06/windows/eventlog/system"><EventID>0</EventID><Type>3</Type><SubType Name="Transfer">0</SubType><Level>255</Level><TimeCreated SystemTime="2016-07-19T09:55:54.2135766Z" /><Source Name="System.ServiceModel" /><Correlation ActivityID="{de1073e0-a063-4b78-a802-e2ea11c2711d}" RelatedActivityID="{00000000-0000-0000-0000-000000000000}" /><Execution ProcessName="Windows Service" ProcessID="6676" ThreadID="4" /><Channel/><Computer>DEV01</Computer></System><ApplicationData></ApplicationData></E2ETraceEvent><E2ETraceEvent xmlns="http://schemas.microsoft.com/2004/06/E2ETraceEvent"><System xmlns="http://schemas.microsoft.com/2004/06/windows/eventlog/system"><EventID>131085</EventID><Type>3</Type><SubType Name="Stop">0</SubType><Level>255</Level><TimeCreated SystemTime="2016-07-19T09:55:54.2135766Z" /><Source Name="System.ServiceModel" /><Correlation ActivityID="{de1073e0-a063-4b78-a802-e2ea11c2711d}" /><Execution ProcessName="Windows Service" ProcessID="6676" ThreadID="4" /><Channel/><Computer>DEV01</Computer></System><ApplicationData><TraceData><DataItem><TraceRecord xmlns="http://schemas.microsoft.com/2004/10/E2ETraceEvent/TraceRecord" Severity="Stop"><TraceIdentifier>http://msdn.microsoft.com/fr-FR/library/System.ServiceModel.Diagnostics.ActivityBoundary.aspx</TraceIdentifier><Description>Limite d'activité.</Description><AppDomain>Windows Service</AppDomain><ExtendedData xmlns="http://schemas.microsoft.com/2006/08/ServiceModel/DictionaryTraceRecord"><ActivityName>Construire ServiceHost 'WCF_Service_Library.Service'.</ActivityName><ActivityType>Construct</ActivityType></ExtendedData></TraceRecord></DataItem></TraceData></ApplicationData></E2ETraceEvent><E2ETraceEvent xmlns="http://schemas.microsoft.com/2004/06/E2ETraceEvent"><System xmlns="http://schemas.microsoft.com/2004/06/windows/eventlog/system"><EventID>0</EventID><Type>3</Type><SubType Name="Transfer">0</SubType><Level>255</Level><TimeCreated SystemTime="2016-07-19T09:55:54.2765741Z" /><Source Name="System.ServiceModel" /><Correlation ActivityID="{00000000-0000-0000-0000-000000000000}" RelatedActivityID="{c002e9ab-b644-4f63-8efe-ce7b77e403e3}" /><Execution ProcessName="Windows Service" ProcessID="6676" ThreadID="4" /><Channel/><Computer>DEV01</Computer></System><ApplicationData></ApplicationData></E2ETraceEvent><E2ETraceEvent xmlns="http://schemas.microsoft.com/2004/06/E2ETraceEvent"><System xmlns="http://schemas.microsoft.com/2004/06/windows/eventlog/system"><EventID>131085</EventID><Type>3</Type><SubType Name="Start">0</SubType><Level>255</Level><TimeCreated SystemTime="2016-07-19T09:55:54.2765741Z" /><Source Name="System.ServiceModel" /><Correlation ActivityID="{c002e9ab-b644-4f63-8efe-ce7b77e403e3}" /><Execution ProcessName="Windows Service" ProcessID="6676" ThreadID="4" /><Channel/><Computer>DEV01</Computer></System><ApplicationData><TraceData><DataItem><TraceRecord xmlns="http://schemas.microsoft.com/2004/10/E2ETraceEvent/TraceRecord" Severity="Start"><TraceIdentifier>http://msdn.microsoft.com/fr-FR/library/System.ServiceModel.Diagnostics.ActivityBoundary.aspx</TraceIdentifier><Description>Limite d'activité.</Description><AppDomain>Windows Service</AppDomain><ExtendedData xmlns="http://schemas.microsoft.com/2006/08/ServiceModel/DictionaryTraceRecord"><ActivityName>Ouvrir ServiceHost 'WCF_Service_Library.Service'.</ActivityName><ActivityType>Open</ActivityType></ExtendedData></TraceRecord></DataItem></TraceData></ApplicationData></E2ETraceEvent><E2ETraceEvent xmlns="http://schemas.microsoft.com/2004/06/E2ETraceEvent"><System xmlns="http://schemas.microsoft.com/2004/06/windows/eventlog/system"><EventID>524333</EventID><Type>3</Type><SubType Name="Information">0</SubType><Level>8</Level><TimeCreated SystemTime="2016-07-19T09:55:54.2765741Z" /><Source Name="System.ServiceModel" /><Correlation ActivityID="{c002e9ab-b644-4f63-8efe-ce7b77e403e3}" /><Execution ProcessName="Windows Service" ProcessID="6676" ThreadID="4" /><Channel/><Computer>DEV01</Computer></System><ApplicationData><TraceData><DataItem><TraceRecord xmlns="http://schemas.microsoft.com/2004/10/E2ETraceEvent/TraceRecord" Severity="Information"><TraceIdentifier>http://msdn.microsoft.com/fr-FR/library/System.ServiceModel.ServiceHostBaseAddresses.aspx</TraceIdentifier><Description>Adresses de base ServiceHost.</Description><AppDomain>Windows Service</AppDomain><Source>Windows_Service.CustomServiceHost/45867655</Source><ExtendedData xmlns="http://schemas.microsoft.com/2006/08/ServiceModel/CollectionTraceRecord"><BaseAddresses><Address>https://myserver.mydomain.fr:443/</Address></BaseAddresses></ExtendedData></TraceRecord></DataItem></TraceData></ApplicationData></E2ETraceEvent><E2ETraceEvent xmlns="http://schemas.microsoft.com/2004/06/E2ETraceEvent"><System xmlns="http://schemas.microsoft.com/2004/06/windows/eventlog/system"><EventID>0</EventID><Type>3</Type><SubType Name="Transfer">0</SubType><Level>255</Level><TimeCreated SystemTime="2016-07-19T09:55:54.2765741Z" /><Source Name="System.ServiceModel" /><Correlation ActivityID="{c002e9ab-b644-4f63-8efe-ce7b77e403e3}" RelatedActivityID="{00000000-0000-0000-0000-000000000000}" /><Execution ProcessName="Windows Service" ProcessID="6676" ThreadID="4" /><Channel/><Computer>DEV01</Computer></System><ApplicationData></ApplicationData></E2ETraceEvent><E2ETraceEvent xmlns="http://schemas.microsoft.com/2004/06/E2ETraceEvent"><System xmlns="http://schemas.microsoft.com/2004/06/windows/eventlog/system"><EventID>131085</EventID><Type>3</Type><SubType Name="Stop">0</SubType><Level>255</Level><TimeCreated SystemTime="2016-07-19T09:55:54.2765741Z" /><Source Name="System.ServiceModel" /><Correlation ActivityID="{c002e9ab-b644-4f63-8efe-ce7b77e403e3}" /><Execution ProcessName="Windows Service" ProcessID="6676" ThreadID="4" /><Channel/><Computer>DEV01</Computer></System><ApplicationData><TraceData><DataItem><TraceRecord xmlns="http://schemas.microsoft.com/2004/10/E2ETraceEvent/TraceRecord" Severity="Stop"><TraceIdentifier>http://msdn.microsoft.com/fr-FR/library/System.ServiceModel.Diagnostics.ActivityBoundary.aspx</TraceIdentifier><Description>Limite d'activité.</Description><AppDomain>Windows Service</AppDomain><ExtendedData xmlns="http://schemas.microsoft.com/2006/08/ServiceModel/DictionaryTraceRecord"><ActivityName>Ouvrir ServiceHost 'WCF_Service_Library.Service'.</ActivityName><ActivityType>Open</ActivityType></ExtendedData></TraceRecord></DataItem></TraceData></ApplicationData></E2ETraceEvent><E2ETraceEvent xmlns="http://schemas.microsoft.com/2004/06/E2ETraceEvent"><System xmlns="http://schemas.microsoft.com/2004/06/windows/eventlog/system"><EventID>0</EventID><Type>3</Type><SubType Name="Transfer">0</SubType><Level>255</Level><TimeCreated SystemTime="2016-07-19T09:56:09.3075479Z" /><Source Name="System.ServiceModel" /><Correlation ActivityID="{00000000-0000-0000-0000-000000000000}" RelatedActivityID="{19dd45d9-e0f7-4ffe-aa8e-4aaf7b5b18ba}" /><Execution ProcessName="Windows Service" ProcessID="6676" ThreadID="4" /><Channel/><Computer>DEV01</Computer></System><ApplicationData></ApplicationData></E2ETraceEvent><E2ETraceEvent xmlns="http://schemas.microsoft.com/2004/06/E2ETraceEvent"><System xmlns="http://schemas.microsoft.com/2004/06/windows/eventlog/system"><EventID>131085</EventID><Type>3</Type><SubType Name="Start">0</SubType><Level>255</Level><TimeCreated SystemTime="2016-07-19T09:56:09.3075479Z" /><Source Name="System.ServiceModel" /><Correlation ActivityID="{19dd45d9-e0f7-4ffe-aa8e-4aaf7b5b18ba}" /><Execution ProcessName="Windows Service" ProcessID="6676" ThreadID="4" /><Channel/><Computer>DEV01</Computer></System><ApplicationData><TraceData><DataItem><TraceRecord xmlns="http://schemas.microsoft.com/2004/10/E2ETraceEvent/TraceRecord" Severity="Start"><TraceIdentifier>http://msdn.microsoft.com/fr-FR/library/System.ServiceModel.Diagnostics.ActivityBoundary.aspx</TraceIdentifier><Description>Limite d'activité.</Description><AppDomain>Windows Service</AppDomain><ExtendedData xmlns="http://schemas.microsoft.com/2006/08/ServiceModel/DictionaryTraceRecord"><ActivityName>Fermer ServiceHost 'WCF_Service_Library.Service'.</ActivityName><ActivityType>Close</ActivityType></ExtendedData></TraceRecord></DataItem></TraceData></ApplicationData></E2ETraceEvent><E2ETraceEvent xmlns="http://schemas.microsoft.com/2004/06/E2ETraceEvent"><System xmlns="http://schemas.microsoft.com/2004/06/windows/eventlog/system"><EventID>524333</EventID><Type>3</Type><SubType Name="Information">0</SubType><Level>8</Level><TimeCreated SystemTime="2016-07-19T09:56:09.3075479Z" /><Source Name="System.ServiceModel" /><Correlation ActivityID="{19dd45d9-e0f7-4ffe-aa8e-4aaf7b5b18ba}" /><Execution ProcessName="Windows Service" ProcessID="6676" ThreadID="4" /><Channel/><Computer>DEV01</Computer></System><ApplicationData><TraceData><DataItem><TraceRecord xmlns="http://schemas.microsoft.com/2004/10/E2ETraceEvent/TraceRecord" Severity="Information"><TraceIdentifier>http://msdn.microsoft.com/fr-FR/library/System.ServiceModel.ServiceHostBaseAddresses.aspx</TraceIdentifier><Description>Adresses de base ServiceHost.</Description><AppDomain>Windows Service</AppDomain><Source>Windows_Service.CustomServiceHost/45867655</Source><ExtendedData xmlns="http://schemas.microsoft.com/2006/08/ServiceModel/CollectionTraceRecord"><BaseAddresses><Address>https://myserver.mydomain.fr:443/</Address></BaseAddresses></ExtendedData></TraceRecord></DataItem></TraceData></ApplicationData></E2ETraceEvent><E2ETraceEvent xmlns="http://schemas.microsoft.com/2004/06/E2ETraceEvent"><System xmlns="http://schemas.microsoft.com/2004/06/windows/eventlog/system"><EventID>0</EventID><Type>3</Type><SubType Name="Transfer">0</SubType><Level>255</Level><TimeCreated SystemTime="2016-07-19T09:56:09.3075479Z" /><Source Name="System.ServiceModel" /><Correlation ActivityID="{19dd45d9-e0f7-4ffe-aa8e-4aaf7b5b18ba}" RelatedActivityID="{00000000-0000-0000-0000-000000000000}" /><Execution ProcessName="Windows Service" ProcessID="6676" ThreadID="4" /><Channel/><Computer>DEV01</Computer></System><ApplicationData></ApplicationData></E2ETraceEvent><E2ETraceEvent xmlns="http://schemas.microsoft.com/2004/06/E2ETraceEvent"><System xmlns="http://schemas.microsoft.com/2004/06/windows/eventlog/system"><EventID>131085</EventID><Type>3</Type><SubType Name="Stop">0</SubType><Level>255</Level><TimeCreated SystemTime="2016-07-19T09:56:09.3075479Z" /><Source Name="System.ServiceModel" /><Correlation ActivityID="{19dd45d9-e0f7-4ffe-aa8e-4aaf7b5b18ba}" /><Execution ProcessName="Windows Service" ProcessID="6676" ThreadID="4" /><Channel/><Computer>DEV01</Computer></System><ApplicationData><TraceData><DataItem><TraceRecord xmlns="http://schemas.microsoft.com/2004/10/E2ETraceEvent/TraceRecord" Severity="Stop"><TraceIdentifier>http://msdn.microsoft.com/fr-FR/library/System.ServiceModel.Diagnostics.ActivityBoundary.aspx</TraceIdentifier><Description>Limite d'activité.</Description><AppDomain>Windows Service</AppDomain><ExtendedData xmlns="http://schemas.microsoft.com/2006/08/ServiceModel/DictionaryTraceRecord"><ActivityName>Fermer ServiceHost 'WCF_Service_Library.Service'.</ActivityName><ActivityType>Close</ActivityType></ExtendedData></TraceRecord></DataItem></TraceData></ApplicationData></E2ETraceEvent><E2ETraceEvent xmlns="http://schemas.microsoft.com/2004/06/E2ETraceEvent"><System xmlns="http://schemas.microsoft.com/2004/06/windows/eventlog/system"><EventID>131073</EventID><Type>3</Type><SubType Name="Information">0</SubType><Level>8</Level><TimeCreated SystemTime="2016-07-19T09:56:09.4795464Z" /><Source Name="System.ServiceModel" /><Correlation ActivityID="{00000000-0000-0000-0000-000000000000}" /><Execution ProcessName="Windows Service" ProcessID="6676" ThreadID="2" /><Channel/><Computer>DEV01</Computer></System><ApplicationData><TraceData><DataItem><TraceRecord xmlns="http://schemas.microsoft.com/2004/10/E2ETraceEvent/TraceRecord" Severity="Information"><TraceIdentifier>http://msdn.microsoft.com/fr-FR/library/System.ServiceModel.Diagnostics.AppDomainUnload.aspx</TraceIdentifier><Description>Déchargement d'un domaine d'application.</Description><AppDomain>Windows Service</AppDomain><ExtendedData xmlns="http://schemas.microsoft.com/2006/08/ServiceModel/DictionaryTraceRecord"><AppDomain.FriendlyName>Windows Service</AppDomain.FriendlyName><ProcessName>Windows Service</ProcessName><ProcessId>6676</ProcessId></ExtendedData></TraceRecord></DataItem></TraceData></ApplicationData></E2ETraceEvent><E2ETraceEvent xmlns="http://schemas.microsoft.com/2004/06/E2ETraceEvent"><System xmlns="http://schemas.microsoft.com/2004/06/windows/eventlog/system"><EventID>131073</EventID><Type>3</Type><SubType Name="Information">0</SubType><Level>8</Level><TimeCreated SystemTime="2016-07-19T09:56:09.4795464Z" /><Source Name="System.ServiceModel" /><Correlation ActivityID="{00000000-0000-0000-0000-000000000000}" /><Execution ProcessName="Windows Service" ProcessID="6676" ThreadID="2" /><Channel/><Computer>DEV01</Computer></System><ApplicationData><TraceData><DataItem><TraceRecord Severity="Information" Channel="Debug" xmlns="http://schemas.microsoft.com/2004/10/E2ETraceEvent/TraceRecord"><TraceIdentifier>http://msdn.microsoft.com/fr-FR/library/System.ServiceModel.Diagnostics.AppDomainUnload.aspx</TraceIdentifier><Description>Déchargement AppDomain. AppDomain.FriendlyName Windows Service, ProcessName Windows Service, ProcessId 6676.</Description><AppDomain>Windows Service</AppDomain></TraceRecord></DataItem></TraceData></ApplicationData></E2ETraceEvent></events>

Thanks for your help!

Reinstall and restart the host service.

Implement the following wcf handlers

serviceHost.Opening += new EventHandler(serviceHost_Opening);
serviceHost.Opened += new EventHandler(serviceHost_Opened);
serviceHost.Closing += new EventHandler(serviceHost_Closing);
serviceHost.Closed += new EventHandler(serviceHost_Closed);
serviceHost.Faulted += new EventHandler(serviceHost_Faulted);
serviceHost.UnknownMessageReceived += new EventHandler<UnknownMessageReceivedEventArgs>(serviceHost_UnknownMessageReceived);

serviceHost.Open();

Check also the windows events and netstat

netstat -aon | find ":443"

to find if the port binding is actually active and what program belongs to that PID.

Please note, don't close the service host after opening it (open wcp in the windows service OnStart and close it in OnStop )

Look also at msdn example for specifying endpoint address in code

Uri baseAddress = new Uri("http://localhost:8000/HelloService");
string address = "http://localhost:8000/HelloService/MyService";

using (ServiceHost serviceHost = new ServiceHost(typeof(HelloService), baseAddress))
{
    serviceHost.AddServiceEndpoint(typeof(IHello), new BasicHttpBinding(), address);
    serviceHost.Open();
    Console.WriteLine("Press <enter> to terminate service");
    Console.ReadLine();
    serviceHost.Close();
}

A final note, I expect you should add

base.InitializeRuntime();

in the end of protected override void InitializeRuntime()

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM