Net.tcp 바인딩을 사용하여 WCF 서비스를 개발 중입니다. 이 서비스는 작업자 역할의 Run 메서드에서 호스팅됩니다. 내 푸른 계정에 배포하늘 에뮬레이터에서 WCF net.TCP 자체 호스팅 - Windows 7
, 그것은 잘 작동하지만 런타임에 예외가 발생합니다 : 대상 컴퓨터가 적극적
때때로을 거부했기 때문에
없음 연결을 만들 수 있습니다을 때 포트 번호를 변경하면 몇 번 작동하지만 다시 연결을 거부하면 포트 번호를 다시 변경해야합니다. ...
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(); } }
일부 서버와 클라이언트 코드 예제를 추가, –
당신은 127.0.0.1:XXXX에 결합되어 주 시겠어요? Windows Azure에서는 절대로 그렇게하지 않을 것입니다. 대신 InstanceEndpoints에서 IPEndpoint를 가져와야합니다. - http://msdn.microsoft.com/en-us/library/microsoft.windowsazure.serviceruntime.roleinstance.instanceendpoints RoleEnvironment.CurrentRoleInstance.InstanceEndpoints [ "yourEndpointName"] – astaykov
예 astaykov , 나는 InstanceEndpoints에서 끝점을 가져 가고 있습니다. 127.255.0.1을 가리 킵니다. 이것이 내가 클라이언트에서 사용하고있는 IP입니다. 그것은 때때로 작동합니다. –