I'm developing a WCF service using Net.tcp Binding. The service is hosted on the Run method of a worker role.
When deployed to my Azure Account, it works fine, but in runtime it throws an exception:
No connection could be made because the target machine actively refused it
Sometimes when I change the port number, it works fine for a couple of times, but then it refuses the connection again and I have to change the port number again...
I made the exceptions in windows firewall, and also shut down the firewall but it doesn't work.
Could it be some constraint on Windows 7? Any help appreciated. Thanks
Edit: I'm adding client and Server code for clarification.
Service configuration:
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);
}
Client:
AppService() //private constructor
{
client = new ServiceRef.ServiceClient();
}
Service call:
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();
}
}