[英]Hosting WCF service as Windows Service?
我已经设法将复杂的WCF服务移至Windows服务。 绑定看起来像这样:
<service behaviorConfiguration="MyAppClientService.CustomValidator_Behavior" name="MyApp.ServiceImplementation.MyAppClientService">
<endpoint binding="netTcpBinding" bindingConfiguration="netTcpRegular" address="Regular" bindingNamespace="http://MyApp.ServiceContracts/2007/11" contract="MyApp.ServiceContracts.IMyAppClientService"/>
<endpoint binding="netTcpBinding" bindingConfiguration="netTcpWindowMessageSecurity" address="Windows" bindingNamespace="http://MyApp.ServiceContracts/2007/11" contract="MyApp.ServiceContracts.IMyAppClientService"/>
<host>
<baseAddresses>
<add baseAddress="net.tcp://localhost:8001/MyAppService/Client"/>
<add baseAddress="http://localhost:8002/MyAppService/Client"/>
</baseAddresses>
</host>
</service>
服务启动后,我浏览: http://localhost:8002/MyAppService/Client
这可以正常工作,并且我也可以看到WSDL。
但是,当我尝试使用Winform客户端连接到该服务时,找不到该服务,这就是该地址在客户端中的样子:
<client>
<endpoint address="net.tcp://localhost:8001/MyAppService/Client/MyAppClientService.svc/Regular" behaviorConfiguration="BasicBehavior" binding="netTcpBinding" bindingConfiguration="NetTcpBinding_IMyAppClientServiceRegular" contract="MyApp.ServiceContracts.IMyAppClientService" name="MyTest_RegularLogin"/>
</client>
当浏览http://localhost:8001/MyAppService/Client
我会得到一个丢失的页面,我想这是正确的,因为它托管在tcp而不是http上?
当服务托管在IIS7(WAS)中时,它工作得很好,但是随后我在客户端使用了一个如下所示的端点:
<endpoint address="net.tcp://localhost/MyAppDev/MyAppClientService.svc/Regular" behaviorConfiguration="BasicBehavior" binding="netTcpBinding" bindingConfiguration="NetTcpBinding_IMyAppClientServiceRegular" contract="MyApp.ServiceContracts.IMyAppClientService" name="MyApp_RegularLogin"/>
注意:常规统计信息,这是常规登录,其中客户端提供用户名和密码(没有Windows登录名)
编辑:
我已经关注了这篇文章: http : //msdn.microsoft.com/zh-cn/library/ms733069.aspx
这就是Windows服务类的样子
public class MyAppWindowsService : ServiceBase
{
public ServiceHost _serviceHost = null;
public MyAppWindowsService()
{
// Name the Windows Service
ServiceName = "MyAppWindowsService";
}
public static void Main()
{
ServiceBase.Run(new MyAppWindowsService());
}
// Start the Windows service.
protected override void OnStart(string[] args)
{
if (_serviceHost != null)
{
_serviceHost.Close();
}
// Create a ServiceHost for the CalculatorService type and
// provide the base address.
_serviceHost = new ServiceHost(typeof(MyApp.ServiceImplementation.MyAppClientService));
// Open the ServiceHostBase to create listeners and start
// listening for messages.
_serviceHost.Open();
}
protected override void OnStop()
{
if (_serviceHost != null)
{
_serviceHost.Close();
_serviceHost = null;
}
}
}
问题是我尝试连接到localhost/MyAppDev/MyAppClientService.svc/Regular
但是它应该是localhost/MyAppDev/Regular
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.