Hosting WCF Service as Windows Service -
i have created wcf service project. has following content in svc file.
<%@ servicehost service="deepak.businessservices.implementation.apiimplementation" factory="deepak.businessservices.implementation.customservicehostfactory"%>
svc reference
http://localhost/deepakgateway/service.svc
service , wsdl generated. want host service windows service. how can it?
i have created "windows service" project ans have following code.
protected override void onstart(string[] args) { if (m_host != null) { m_host.close(); } uri httpurl = new uri("http://localhost/deepakgateway/service.svc"); m_host = new servicehost (typeof(?????? fill here?), httpurl); //add service endpoint m_host.addserviceendpoint (typeof(?????? fill here?), ), new wshttpbinding(), ""); //enable metadata exchange servicemetadatabehavior smb = new servicemetadatabehavior(); smb.httpgetenabled = true; m_host.description.behaviors.add(smb); //start service m_host.open(); }
you need add type of class implements service contract in servicehost
constructor, , type of service contract in addserviceendpoint
assuming service implementation class looks this:
namespace deepak.businessservices.implementation { public class apiimplementation : iapiimplementation { .... } }
then need:
m_host = new servicehost(typeof(apiimplementation), httpurl); m_host.addserviceendpoint(typeof(iapiimplementation), new wshttpbinding(), "");
- the service host needs know (concrete) type of service class host
- the endpoint needs know service contract (interface) exposes
Comments
Post a Comment