WCF with multiple named ends

I have two services that I want to interact with through named pipes. I tried this in two ways, creating two separate ServiceHosts and creating multiple endpoints on the same service. The first service works fine whether I have a second service or not. For the second service in both cases, I either get an error not found by the endpoint due to the fact that it does not find the named pipe (separate services) or the address filter problem (which setting for Any does not fix). I checked and double checked my settings, but I'm at a dead end.

Both server and client use the same assembly, which has a contract:

[ServiceContract(CallbackContract = typeof(IServiceCallback1), SessionMode = SessionMode.Required)]
public interface IService1
{
    ....
}
[ServiceContract]
public interface IService2
{
    ...
}

Here's the server side:

[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();
}

(, , , Service2 , Service1)

:

<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, , .

+3

Source: https://habr.com/ru/post/1781347/


All Articles