我最近实现了一个CustomServiceHostFactory,并想知道如何通过在代码中命中断点来调试它。这是工厂:
public class CustomHostFactory : ServiceHostFactory
{
protected override ServiceHost CreateServiceHost(Type serviceType, Uri[] baseAddresses)
{
ServiceHost host = new ServiceHost(serviceType, baseAddresses);
//configure WsHttpBinding
ConfigureServiceThrottling(host);
return host;
}
private void ConfigureWshttpBinding(ServiceHost host)
{
//Do something here....
}
private void ConfigureServiceThrottling(ServiceHost host)
{
ServiceThrottlingBehavior throttle = host.Description.Behaviors.Find<ServiceThrottlingBehavior>();
if (throttle == null)
{
throttle = new ServiceThrottlingBehavior
{
MaxConcurrentCalls = 100,
MaxConcurrentSessions = 100,
MaxConcurrentInstances = 100
};
host.Description.Behaviors.Add(throttle);
}
}
}
我在一个空的Web项目中创建它,这里是相关的Web.config内容。
<service name="Company.Project.Business.Services.AccountService" behaviorConfiguration="MyServiceTypeBehaviors">
<endpoint address=""
binding="basicHttpBinding"
contract="Company.Project.Business.Contracts.Service.IAccountService"/>
<endpoint contract="IMetadataExchange" binding="mexHttpBinding" address="mex" />
</service>
<service name="Company.Project.Business.Services.AccountClassService" behaviorConfiguration="MyServiceTypeBehaviors">
<endpoint address=""
binding="basicHttpBinding"
contract="Company.Project.Business.Contracts.Service.IAccountClassService"/>
<endpoint contract="IMetadataExchange" binding="mexHttpBinding" address="mex" />
</service>
</services>
<serviceHostingEnvironment>
<!-- where virtual .svc files are defined -->
<serviceActivations>
<add service="Company.Project.Business.Services.AccountService"
relativeAddress="AccountService.svc"
factory="Company.Project.WebHost.CustomHostFactory"/>
<add service="Company.Project.Business.Services.AccountClassService"
relativeAddress="AccountClassService.svc"
factory="Company.Project.WebHost.CustomHostFactory"/>
</serviceActivations>
</serviceHostingEnvironment>
我将此发布到IIS并且可以成功浏览并使用这些服务。例如,这是一条路径。
http://company.server.local/Project/Account/AccountService.svc
我现在正尝试以编程方式将WsHttpBinding应用于打开/关闭/发送超时,readerQuotas等。我试图在代码中执行此操作,如果我可以进入CustomeHostFactory进行调试但不知道它会有所帮助怎么做。任何帮助深表感谢。谢谢。
答案 0 :(得分:0)
好的,我在这里完全糊涂了。我没有尝试附加到w3wp进程,而只是将CustomHostFactory设置为Visual Studio中的启动项目。我在受保护的覆盖ServiceHost CreateServiceHost方法中放置了一个断点。
然后,当我运行项目时,http://localhost:58326/出现在浏览器中。然后,我必须实际浏览到这样的端点:http://localhost:58326/Account/AccountService.svc以便达到断点。
现在我可以调试我的服务的编程配置。希望这有助于其他人。