[英]wcf self hosting multiple service
In my project I have two services Service1 and Service2 (ieservice contracts).I want these two to be self hosted using console.For this I am using service named "myservice" and implementing both interfaces ie IService1 and IService2 like 在我的项目中,我有两个服务Service1和Service2(即服务合同)。我想使用控制台对这两个服务进行自我托管。为此,我使用名为“ myservice”的服务并实现两个接口,例如IService1和IService2
public class myservice : IService1,IService2
...
....
ServiceHost serviceHost = new ServiceHost(typeof(myservice));
serviceHost.Open();
Endpoints used : 使用的端点:
<service behaviorConfiguration="myBehavior" name="myservice">
<endpoint address="sa1" binding="netTcpBinding" contract="IService1"/>
<endpoint address="sa2" binding="netTcpBinding" contract="IService2"/>
<host>
<baseAddresses>
<add baseAddress="net.tcp://localhost:8001/" />
</baseAddresses>
</host>
</service>
I want these two be seperate service ie service named Service1 and Service2 (instead of myservice) with tcp binding and self hosting.Any code/help/suggestions appreciated. 我希望这两个是单独的服务,即具有tcp绑定和自托管功能的名为Service1和Service2的服务(而不是myservice)。任何代码/帮助/建议都值得赞赏。
If you must have two separate services - then you need two separate service implementation classes and also two separate ServiceHost
instances: 如果必须具有两个单独的服务-那么就需要两个单独的服务实现类以及两个单独的
ServiceHost
实例:
public class Service1 : IService1
{
...
}
public class Service2 : IService2
{
...
}
ServiceHost serviceHost1 = new ServiceHost(typeof(Service1));
serviceHost1.Open();
ServiceHost serviceHost2 = new ServiceHost(typeof(Service2));
serviceHost2.Open();
Endpoint config: 端点配置:
<service name="YourNamespace.Service1" behaviorConfiguration="myBehavior" >
<endpoint address="sa1" binding="netTcpBinding" contract="IService1" />
<host>
<baseAddresses>
<add baseAddress="net.tcp://localhost:8001/" />
</baseAddresses>
</host>
</service>
<service name="YourNamespace.Service2" behaviorConfiguration="myBehavior" >
<endpoint address="sa2" binding="netTcpBinding" contract="IService2" />
<host>
<baseAddresses>
<add baseAddress="net.tcp://localhost:8002/" />
</baseAddresses>
</host>
</service>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.