0

Net.tcp バインディングを使用して WCF サービスを開発しています。サービスは、worker ロールの 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();
    }
}
4

2 に答える 2

0

「何が起こっているのかわかりました。ワーカーロールに割り当てられたIPは動的です。127.255.0.0の場合と127.255.0.1の場合があります。」

あなたは私と同じ過ちを犯していると思います。ここを参照してください:

Azure Compute Emulator:個々のインスタンスのIPを制御することは可能ですか?

于 2012-08-31T06:50:14.143 に答える
0

問題は散発的であり、ポートの変更はしばらくの間機能するため、net.tcp ポート共有がサービスと競合している可能性があります。そのため、net.tcp ベースの WCF アプリケーション (Web または Worker ロールで) をローカルで使用しているため、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();
于 2012-08-30T22:41:21.067 に答える