2

WCF self-hosted HTTPWeb サービスの作成に成功しました。私はwebserviceHostこのサービスを作成するために使用します。ファイルに変更を加えていませんweb.config。これが私のコードです:

インスタンス.cs:

 [OperationContract, WebInvoke(Method = "GET", UriTemplate = "/getstatus/", ResponseFormat = WebMessageFormat.Json)]
    bool getstatus();

サービス.cs:

 public bool getstatus()
    {
        return true;
    }

BindingWS.cs

 void bindservice()
    {
        try
        {
            m_running = true;
            // Start the host
            m_serviceHost = new WebServiceHost(typeof(Swiper.cs), new Uri(http://localhost:8083"));
            ServiceEndpoint ep = m_serviceHost.AddServiceEndpoint(typeof(Instace.cs), new WebHttpBinding(), "");
            m_serviceHost.Open();
            while (m_running)
            {
                // Wait until thread is stopped
                Thread.Sleep(SleepTime);
            }

            // Stop the host
            m_serviceHost.Close();
        }
        catch (Exception e)
        {
            Console.WriteLine(e.Message);
            if (m_serviceHost != null)
            {
                m_serviceHost.Close();
            }
        }
    }

上記のコードは で実行しても問題なく動作WCFHtppます。しかし、どのように私はそれをに変換しHTTPSます。私は非常に多くのブログをフォローしていますが、何も得られませんでした。それは可能ですか?

4

1 に答える 1

1

基本的に、ホストで使用しているポート番号に対して証明書を手動で登録する必要があります。これを達成する方法の詳細は次のとおりです

http://msdn.microsoft.com/en-us/library/ms733791.aspx

更新21/2/13:

上記のようにドメインの証明書を登録している場合は、上記のコードにいくつかの調整を加えることで、これを機能させることができます。これは、コンソールアプリケーションをホストとして使用するサンプルコードです。HTH。

    using (var serviceHost = new WebServiceHost(typeof(Swiper), new Uri("https://localhost:8083")))
        {
            var secureWebHttpBinding = new WebHttpBinding(WebHttpSecurityMode.Transport) { Name = "secureHttpWeb" };
            serviceHost.AddServiceEndpoint(typeof(ISwiper), secureWebHttpBinding, "");
            serviceHost.Open();
            Console.WriteLine("Service running...");
            Console.WriteLine("Press any key to stop service.");
            Console.ReadLine();

            // Stop the host
            serviceHost.Close();
        }
于 2013-02-18T10:11:01.943 に答える