2012-08-30 5 views
0

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

일부 서버와 클라이언트 코드 예제를 추가, –

+0

당신은 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

+0

예 astaykov , 나는 InstanceEndpoints에서 끝점을 가져 가고 있습니다. 127.255.0.1을 가리 킵니다. 이것이 내가 클라이언트에서 사용하고있는 IP입니다. 그것은 때때로 작동합니다. –

답변

0

문제가 산발적이고 변화하는 포트가 잠시 동안 작동으로, 그것은 가능성이있다 net.tcp 포트 공유가 서비스와 충돌합니다. 따라서 net.tcp 기반 WCF 응용 프로그램 (웹 또는 작업자 역할)을 로컬로 사용하고 있으므로 net.tcp 포트 공유 서비스가 효과적으로 실행되도록 설정해야합니다. 서비스 시작 코드 또한

당신이 설정하여 기본 IP 주소와 아래 포트 뭔가 제대로 바인딩 할 수 있습니다

NetTcpBinding binding = new NetTcpBinding(); 
binding.PortSharingEnabled = true; 
// Setup other binding properties here. 

// Service_NAME is the Serice Name in this project 
ServiceHost host = new ServiceHost(typeof(Service_NAME)); 

//Endpoint1 is the End point name you have setup in your Windows Azure Role property 
string serviceIP = RoleEnvironment.CurrentRoleInstance.InstanceEndpoints["Endpoint1"].IPEndpoint.Address.ToString(); 
string servicePort = RoleEnvironment.CurrentRoleInstance.InstanceEndpoints["Endpoint1"].IPEndpoint.Port.ToString(); 
// 
string address = String.Format("net.tcp://{0}:{1}/SERVICE_METHOD*", serviceIP, servicePort); 
host.AddServiceEndpoint(typeof(YOUR_SERVICE_TYPE), binding, address); 
host.Open(); 
+0

포트 공유가 활성화되어 있고 예, CurrentRoleInstance를 사용하여 IP 및 포트를 사용하고 있습니다. 일부 코드를 추가하기 위해 내 게시물을 편집 중입니다. –