Мне трудно найти несколько служб WCF. Я размещаю службы WCF в своем приложении консоли сервера, и после запуска приложения я могу успешно открыть конечные точки ServiceHost. Мне удалось успешно добавить ссылку WCFTestService для одного клиента, но когда я пытаюсь добавить ссылку WCFTestService2 (ссылки на правый щелчок-> добавить ссылку на службу-> найти службу и нажать ok) для другого клиента, я получаю странные ошибки:WCF - настройка более 1 WCF-сервиса с помощью NetTcpBinding
System.ServiceModel.AddressAlreadyInUseException: Receiver already exists at the endpoint IP 0.0.0.0:8523. It could happen so if another application listens at this endpoint or service host contains many endpoints of services with the same endpoint IP but with invalid binding configurations---> System.Net.Sockets.SocketException: Only one usage of each socket address (protocol/address/port) is normally allowed
in System.Net.Sockets.Socket.DoBind(EndPoint endPointSnapshot, SocketAddress socketAddress)
in System.Net.Sockets.Socket.Bind(EndPoint localEP)
in System.ServiceModel.Channels.SocketConnectionListener.Listen()
--- End of inner exceptions stack trace ---
in System.ServiceModel.Channels.SocketConnectionListener.Listen()
in System.ServiceModel.Channels.ExclusiveTcpTransportManager.OnOpen()
in System.ServiceModel.Channels.TransportManager.Open(TransportChannelListener channelListener)
in System.ServiceModel.Channels.TransportManagerContainer.Open(SelectTransportManagersCallback selectTransportManagerCallback)
in System.ServiceModel.Channels.TransportChannelListener.OnOpen(TimeSpan timeout)
in System.ServiceModel.Channels.ConnectionOrientedTransportChannelListener.OnOpen(TimeSpan timeout)
in System.ServiceModel.Channels.TcpChannelListener`2.OnOpen(TimeSpan timeout)
in System.ServiceModel.Channels.CommunicationObject.Open(TimeSpan timeout)
w System.ServiceModel.Dispatcher.ChannelDispatcher.OnOpen(TimeSpan timeout)
in System.ServiceModel.Channels.CommunicationObject.Open(TimeSpan timeout)
in System.ServiceModel.ServiceHostBase.OnOpen(TimeSpan timeout)
in System.ServiceModel.Channels.CommunicationObject.Open(TimeSpan timeout)
in Microsoft.Tools.SvcHost.ServiceHostHelper.OpenService(ServiceInfo info)
System.Net.Sockets.SocketException (0x80004005): Tylko jedno użycie każdego adresu gniazda (protokół/adres sieciowy/port) jest normalnie dozwolone
in System.Net.Sockets.Socket.DoBind(EndPoint endPointSnapshot, SocketAddress socketAddress)
in System.Net.Sockets.Socket.Bind(EndPoint localEP)
in System.ServiceModel.Channels.SocketConnectionListener.Listen()
Моя консоль хост-приложение:
static void Main(string[] args)
{
try
{
ServiceHost selfHost = new ServiceHost(typeof(contractImplementation1), new Uri("net.tcp://localhost:8523/WCFTestService"));
selfHost.Open();
selfHost = new ServiceHost(typeof(contractImplementation2), new Uri("net.tcp://localhost:8523/WCFTestService2"));
selfHost.Open();
Console.WriteLine();
Console.WriteLine("Press <ENTER> to terminate service.");
Console.WriteLine();
Console.ReadLine();
}
catch (CommunicationException ce)
{
Console.WriteLine("An exception occurred: {0}", ce.Message);
}
}
app.config
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<system.serviceModel>
<behaviors>
<serviceBehaviors>
<behavior name="WCFServices.MyServiceBehavior">
<serviceMetadata httpGetEnabled="false" httpsGetEnabled="false" />
<serviceDebug includeExceptionDetailInFaults="false" />
</behavior>
</serviceBehaviors>
</behaviors>
<services>
<service behaviorConfiguration="WCFServices.MyServiceBehavior"
name="WcfServices.contractImplementation1">
<endpoint address="" binding="netTcpBinding" bindingConfiguration=""
name="NetTcpBindingEndpoint" contract="WcfServices.IcontractImplementation1">
<identity>
<dns value="localhost" />
</identity>
</endpoint>
<endpoint address="mex" binding="mexTcpBinding" bindingConfiguration=""
name="MexTcpBindingEndpoint" contract="IMetadataExchange" />
<host>
<baseAddresses>
<add baseAddress="net.tcp://localhost:8523/WCFTestService" />
</baseAddresses>
</host>
</service>
<service behaviorConfiguration="WCFServices.MyServiceBehavior"
name="WcfServices.contractImplementation2">
<endpoint address="" binding="netTcpBinding" bindingConfiguration=""
contract="WcfServices.IcontractImplementation2">
<identity>
<dns value="localhost" />
</identity>
</endpoint>
<endpoint address="mex" binding="mexTcpBinding" bindingConfiguration=""
contract="IMetadataExchange" />
<host>
<baseAddresses>
<add baseAddress="net.tcp://localhost:8523/WCFTestService2" />
</baseAddresses>
</host>
</service>
</services>
</system.serviceModel>
</configuration>
Если кто-то может указать мне направление, чтобы решить эту проблему, я бы высоко повыш это.
Измените порт на одном из хостов. –