首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何使用HTTPS访问WCF WebServiceHost端点?

如何使用HTTPS访问WCF WebServiceHost端点?
EN

Stack Overflow用户
提问于 2013-02-18 10:04:16
回答 1查看 5.3K关注 0票数 2

我已经成功地创建了WCF self-hosted HTTP web服务。我使用webserviceHost创建这个服务。我没有对web.config文件做任何修改。这是我的代码:

Instance.cs:

代码语言:javascript
复制
 [OperationContract, WebInvoke(Method = "GET", UriTemplate = "/getstatus/", ResponseFormat = WebMessageFormat.Json)]
    bool getstatus();

service.cs:

代码语言:javascript
复制
 public bool getstatus()
    {
        return true;
    }

BindingWS.cs

代码语言:javascript
复制
 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();
            }
        }
    }

上面的代码在Htpp上运行Htpp很好。而是我如何把它转换成HTTPS。我跟踪了那么多博客,但什么也没得到。有可能做到吗?

EN

回答 1

Stack Overflow用户

发布于 2013-02-18 10:11:01

基本上,您需要根据您在主机中使用的端口号手动注册证书。以下是如何实现这一目标的一些详细信息

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

更新21/2/13:

如果您已经为上面描述的域注册了证书,那么您应该能够通过对上面的代码进行一些调整来实现这个功能。下面是一些使用控制台应用程序作为主机的示例代码。HTH。

代码语言:javascript
复制
    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();
        }
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/14933696

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档