我想通过命名管道与两个服务进行交互。我尝试了这两种方法,既可以创建两个独立的ServiceHost,也可以通过在单个服务上创建多个端点。无论我是否有第二项服务,第一项服务都能完美运作。对于这两种情况下的第二个服务,我得到一个端点未找到错误,因为它没有找到命名管道(单独的服务)或地址过滤器问题(设置为Any不能修复)。我已经检查并仔细检查了我的设置,但我很难过。
服务器和客户端都使用具有合同的相同程序集:
[ServiceContract(CallbackContract = typeof(IServiceCallback1), SessionMode = SessionMode.Required)]
public interface IService1
{
....
}
[ServiceContract]
public interface IService2
{
...
}
这是服务器端:
[ServiceBehavior(InstanceContextMode = InstanceContextMode.PerSession, ConcurrencyMode = ConcurrencyMode.Reentrant, IncludeExceptionDetailInFaults = true)]
class Service1Impl : IService1
{
...
}
[ServiceBehavior(InstanceContextMode = InstanceContextMode.PerSession, IncludeExceptionDetailInFaults = true)]
class IService2Impl : IService2
{
...
}
...
serviceHost1 = new ServiceHost(typeof(Service1Impl));
serviceHost2 = new ServiceHost(typeof(Service2Impl));
try
{
serviceHost2.Open();
serviceHost1.Open();
}
(是的,我以相反的顺序打开它们,因为如果它可以连接到Service1,则客户端进程假定Service2可用)
以下是我对服务的配置:
<system.serviceModel>
<services>
<service name="Service1Impl" behaviorConfiguration="myServiceBehavior">
<endpoint address="" binding="netNamedPipeBinding" contract="IService1"/>
<host>
<baseAddresses>
<add baseAddress="net.pipe://localhost/Service1"/>
</baseAddresses>
</host>
</service>
<service name="Service2Impl" behaviorConfiguration="myServiceBehavior">
<endpoint address="" binding="netNamedPipeBinding" contract="IService2"/>
<host>
<baseAddresses>
<add baseAddress="net.pipe://localhost/Service2"/>
</baseAddresses>
</host>
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior name="myServiceBehavior">
<serviceDebug includeExceptionDetailInFaults="true"/>
</behavior>
</serviceBehaviors>
</behaviors>
</system.serviceModel>
客户端我不使用配置并将其用于:
public class Service2Client: ClientBase<IService2>, IService2
{
public Service2Client()
: base(new NetNamedPipeBinding(), new EndpointAddress("net.pipe://localhost/Service2"))
{
}
}
这里有什么我想念的吗?就像我说的,我可以连接并在第一个服务上调用就好了,但第二个得到EndpointNotFoundException抱怨它找不到命名管道。