Я разрабатываю службу WCF, используя привязку Net.tcp. Служба размещается в методе Run рабочей роли.
При развертывании в моей учетной записи Azure он работает нормально, но во время выполнения выдает исключение:
Соединение не может быть установлено, потому что целевая машина активно отказывается от него.
Иногда, когда я меняю номер порта, он пару раз работает нормально, но потом снова отказывается от соединения, и мне снова приходится менять номер порта...
Я сделал исключения в брандмауэре Windows, а также отключил брандмауэр, но он не работает.
Может быть, это какое-то ограничение на Windows 7? Любая помощь приветствуется. Спасибо
Изменить: я добавляю клиентский и серверный код для уточнения.
Конфигурация службы:
using (ServiceHost host = new ServiceHost(typeof(XMPPService)))
{
string ip = RoleEnvironment.CurrentRoleInstance.InstanceEndpoints["tcpinput"].IPEndpoint.Address.ToString();
int tcpport = RoleEnvironment.CurrentRoleInstance.InstanceEndpoints["tcpinput"].IPEndpoint.Port;
int mexport = RoleEnvironment.CurrentRoleInstance.InstanceEndpoints["mexinput"].IPEndpoint.Port;
ServiceMetadataBehavior metadatabehavior = new ServiceMetadataBehavior();
host.Description.Behaviors.Add(metadatabehavior);
ServiceDebugBehavior behavior = host.Description.Behaviors.Find<ServiceDebugBehavior>();
ServiceThrottlingBehavior tho = new ServiceThrottlingBehavior();
tho.MaxConcurrentCalls = 10000;
tho.MaxConcurrentInstances = 1000;
tho.MaxConcurrentSessions = 1000;
host.Description.Behaviors.Add(tho);
if (behavior == null)
{
host.Description.Behaviors.Add(new ServiceDebugBehavior() { IncludeExceptionDetailInFaults = true });
}
else
{
if (!behavior.IncludeExceptionDetailInFaults)
{
behavior.IncludeExceptionDetailInFaults = true;
}
}
Binding mexBinding = MetadataExchangeBindings.CreateMexTcpBinding();
string mexlistenurl = string.Format("net.tcp://{0}:{1}/XMPPServiceMetaDataEndpoint", ip, mexport);
string mexendpointurl = string.Format("net.tcp://{0}:{1}/XMPPServiceMetaDataEndpoint", ip, mexport);
host.AddServiceEndpoint(typeof(IMetadataExchange), mexBinding, mexendpointurl, new Uri(mexlistenurl));
NetTcpBinding tcpBinding = new NetTcpBinding(SecurityMode.None);
tcpBinding.CloseTimeout = TimeSpan.FromMinutes(2);
tcpBinding.ReceiveTimeout = TimeSpan.FromDays(23);
tcpBinding.OpenTimeout = TimeSpan.FromMinutes(3);
tcpBinding.SendTimeout = TimeSpan.FromMinutes(1);
tcpBinding.PortSharingEnabled = true;
tcpBinding.MaxConnections = 10000;
tcpBinding.MaxConnections = 100;
// tcpBinding.ListenBacklog = 1000000;
tcpBinding.ReliableSession.InactivityTimeout = TimeSpan.FromSeconds(90);
tcpBinding.ReliableSession.Enabled = true;
// Add the endpoint for MyService
string listenurl = string.Format("net.tcp://{0}:{1}/ServiceEndpoint", ip, tcpport);
string endpointurl = string.Format("net.tcp://{0}:{1}/ServiceEndpoint", ip, tcpport);
host.AddServiceEndpoint(typeof(IXMPPService), tcpBinding, endpointurl, new Uri(listenurl));
host.Open();
Thread.Sleep(Timeout.Infinite);
}
Клиент:
AppService() //private constructor
{
client = new ServiceRef.ServiceClient();
}
Сервисный звонок:
bool isAvailable = false;
try
{
isAvailable=client.IsAvailable(_ixo.IMBot.IMEmail, _ixo.Operator.IMClients.First().IMEmail);
}
catch
{
if (client.InnerChannel.State == System.ServiceModel.CommunicationState.Faulted)
{
client.InnerChannel.Abort();
client = new ServiceRef.ServiceClient();
}
}