如何在IIS7.5上托管自定义wcf应用程序(服务器)?
我使用自定义wcf应用程序作为wcf服务器,方法是:如何在IIS7.5上托管自定义wcf应用程序(服务器)?,wcf,Wcf,我使用自定义wcf应用程序作为wcf服务器,方法是: ServiceHost<AlertService> alertServiceHost = new ServiceHost<AlertService>(); configuredEndpoints = alertServiceHost.Description.Endpoints; alertServiceHost.Open(); ServiceHost alertServiceHost=new ServiceHost(
ServiceHost<AlertService> alertServiceHost = new ServiceHost<AlertService>();
configuredEndpoints = alertServiceHost.Description.Endpoints;
alertServiceHost.Open();
ServiceHost alertServiceHost=new ServiceHost();
configuredEndpoints=alertServiceHost.Description.Endpoints;
alertServiceHost.Open();
现在,我在生产部署方面遇到了一个问题,即IIS7.5
我不知道如何在IIS上部署。因为我只知道我必须为IIS上的主机创建svc文件。现在,我只有控制台应用程序作为wcf服务工作
如何将其转换为部署在IIS上
多谢各位 在IIS中托管时,您不会自己创建ServiceHost。这是IIS的责任,也是.svc文件存在的原因。Svc文件指示工作进程如何以及应该承载哪个服务 Svc文件由简单指令(标记)组成:
这是托管本地创建服务的.svc文件的示例,但您可以省略codebeahind
属性,并使用service
属性中的完整类型描述从另一个程序集托管服务类
另请选中。如果要在IIS托管方案中使用自定义服务主机,则需要提供一个将返回该类型服务主机的自定义
ServiceHostFactory
,并在SVC文件中配置该服务主机工厂
基本上,您的自定义服务主机工厂必须从ServiceHostFactory
派生出来,并重写一个返回自定义服务主机实例的方法—大致如下:
public class MyOwnServiceHostFactory : ServiceHostFactory
{
protected override ServiceHost CreateServiceHost(Type t, Uri[] baseAddresses)
{
return new MyOwnCustomServiceHost(t, baseAddresses);
}
public override ServiceHostBase CreateServiceHost(string service, Uri[] baseAddresses)
{
// The service parameter is ignored here because we know our service.
ServiceHost serviceHost = new ServiceHost(typeof(HelloService), baseAddresses);
return serviceHost;
}
}
在SVC文件中,您现在需要:
<%@ ServiceHost Language="C#" Debug="true"
Service="YourNamespace.YourService"
Factory="YourNamespace.MyOwnServiceHostFactory" %>
阅读更多关于:
<%@ ServiceHost Language="C#" Debug="true"
Service="YourNamespace.YourService"
Factory="YourNamespace.MyOwnServiceHostFactory" %>