我已经成功地创建了WCF self-hosted HTTP web服务。我使用webserviceHost创建这个服务。我没有对web.config文件做任何修改。这是我的代码:
Instance.cs:
[OperationContract, WebInvoke(Method = "GET", UriTemplate = "/getstatus/", ResponseFormat = WebMessageFormat.Json)]
bool getstatus();service.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();
}
}
}上面的代码在Htpp上运行Htpp很好。而是我如何把它转换成HTTPS。我跟踪了那么多博客,但什么也没得到。有可能做到吗?
发布于 2013-02-18 10:11:01
基本上,您需要根据您在主机中使用的端口号手动注册证书。以下是如何实现这一目标的一些详细信息
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();
}https://stackoverflow.com/questions/14933696
复制相似问题