开发者

Selfhosted WCF and SSL (Again)

I've configured ssl usign httpcfg set ssl, after this I've written next code:

using System;
using System.Net;
using System.Security.Cryptography.X509Certificates;
using System.ServiceModel;
using System.ServiceModel.Description;
using System.ServiceModel.Security;

namespace SelfHost
{
    internal class Program
    {
        private static void Main(string[] args)
        {
            string addressHttps = String.Format("https://{0}:8000/hello", Dns.GetHostEntry("").HostName);

            var wsHttpBinding = new WSHttpBinding();
            wsHttpBinding.Security.Mode = SecurityMode.Transport;
            wsHttpBinding.Security.Transport.ClientCredentialType = HttpClientCredentialType.Certificate;
            var serviceHost = new ServiceHost(typeof (HelloWorldService),new Uri(addressHttps));
            Type endpoint = typeof (IHelloWorldService);
            serviceHost.AddServiceEndpoint(endpoint, wsHttpBinding, "MyService");

            serviceHost.Credentials.ServiceCertificate.SetCertificate(
                StoreLocation.LocalMachine,
                StoreName.My,
                X509FindType.FindBySubjectName, "myhostname");
            serviceHost.Credentials.ClientCertificate.Authentication.CertificateValidationMode =
                X509CertificateValidationMode.PeerOrChainTrust;
            var smb = new ServiceMetadataBehavior();
            //            smb.HttpGetEnabled = true;
            smb.HttpsGetEnabled = true;
//            smb.HttpsGetUrl = new Uri(addressHttps);
            smb.MetadataExporter.PolicyVersion = PolicyVersion.Policy15;

            serviceHost.Description.Behaviors.Add(smb);
            try
            {
                serviceHost.Open();

                string address = serviceHost.Description.Endpoints[0].ListenUri.AbsoluteUri;
                Console.WriteLine("Listening @ {0}", address);
                Console.WriteLine("Press enter to close the service");
                Console.ReadLine();
                serviceHost.Close();
            }
            catch (CommunicationException ce)
            {
                Console.WriteLine("A commmunication error occurred: {0}", ce.Message);
                Console.WriteLine();
            }
            catch (Exception exc)
            {
                Console.WriteLine("An unforseen error occurred: {0}", exc.Message);
                Console.ReadLine();
            }
        }
    }

    [ServiceContract]
    public interface IHelloWorldService
    {
        [OperationContract]
        string SayHello(string name);
    }

    public class HelloWorldService : IHelloWorldService
    {
        #region IHelloWorldService Members

        public string SayHello(string name)
        {
            return string.Format("Hello, {0}", name);
        }

        #endregion
    }
}

Currently I'm receiving error:


A commmunication error occurred: HTTP could not register URL https://+:8000/hello/. Another application has already registered this URL with HTTP.SYS.

The query httpcfg.exe query ssl returns next info:

IP : 0.0.0.0:8000
Hash : 8e3d19c8778713e544fdd7 f5d8213d37a1757ca
Guid : {06a1ec10-73cc-4a57-828f-17dc7dd444d3}
CertStoreName : MY
CertCheckMode : 0
Revocation开发者_StackOverflow中文版FreshnessTime : 0
UrlRetrievalTimeout : 0
SslCtlIdentifier :
SslCtlStoreName :
Flags : 0
----------------------------------------------------------------------------
IP : myip:8000
Hash : 8e3d19c8778713e544fdd7 f5d8213d37a1757ca
Guid : {50bf66e2-807e-4651-b7af-e25fc2a25cac}
CertStoreName : MY
CertCheckMode : 0
RevocationFreshnessTime : 0
UrlRetrievalTimeout : 0
SslCtlIdentifier :
SslCtlStoreName :
Flags : 0
----------------------------------------------------------------------------

How to fix this error? Thanks.


I have found solution, please see thread

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜