您的位置:首页 > 其它

Self-host vs Managed-host rest service and end points

2017-03-26 08:43 387 查看
ServiceHosts

Servicehost namespace and class is the program model provided by WCF to hsot the web service in executable process that load with CLR.

WebServiceHost is derive from servicehost which is more web service friendly, it saves you the effort to create endpoints as long as your service provide just one type of contract. and its default binding is webhttpbinding.

The code below is fully functional given the endpoints creation is totally wiped out

WebServiceHost host;
var binding = new WebHttpBinding(WebHttpSecurityMode.None);
binding.CrossDomainScriptAccessEnabled = true;

Uri uri = new Uri(_address);
Uri[] baseAddresses = new Uri[] { uri };

host = new WebServiceHost(_servicetype, uri);
//host.AddServiceEndpoint(_contractype, binding, "/workorders").EndpointBehaviors.Add(new WebHttpBehavior());
//host.AddServiceEndpoint(_contractype, binding, "").EndpointBehaviors.Add(new WebHttpBehavior());
return host;


Self host vs managed host

Self host web service means the life time, security and configuration is managed by executable process it self. the ServiceHost provide a method Open() and Close(), which allows you to on/off the webservice container or host

public void StartupStub()
{
host = base.CreateEndPoint();
host.Open();
}

public void StopStub()
{
if (host != null)
{ host.Close(); }
}


View Code

in the contrast, Managed host ones are managed by IIS.
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: