1

Azure 開発ファブリックで IIS アプリケーションをホストしています。

アプリケーションが Azure コンピューティング エミュレーターにデプロイされると、5100 付近のポートでリッスンする一時的な IIS アプリケーションが作成されます。パブリック エンドポイントからの着信要求は、このポートにリダイレクトされます。

ただし、Azure 開発ファブリックは、プロジェクト構成で宣言されたパブリック ポートを常に使用するとは限りません。したがって、たとえば、アプリケーションはパブリック ポート 80 を公開する必要がありますが、これを実行すると、ほとんどの場合ポート 81 になりますが、場合によってはポート 82 などになります。

したがって、アプリケーションで作成された URL が正しいことを確認できます。この外部ポートが何であるかを知りたいです。

残念ながらRequest.Url.Port、これは一時アプリケーションのポート番号であるため、単純に見ることはできません。通常RoleEnvironment.CurrentRoleInstance.InstanceEndpointsは 5100 です。サーバーから見た 5100 以降のポートも返すため、どちらも機能しません。

4

4 に答える 4

1

Figured this out by using Reflector to look into csrun.exe.

It seems that the SDK DLL Microsoft.ServiceHost.Tools.DevelopmentFabric is the key to this, in particular the methods FabricClient.GetServiceDeployments() and FabricClient.GetServiceInformation(). So:

using System; using Microsoft.ServiceHosting.Tools.DevelopmentFabric;

class Program
{
    static void Main(string[] args)
    {
        FabricClient client = FabricClient.CreateFabricClient();

        foreach (string tenantName in client.GetServiceDeployments())
        {
            var information = client.GetServiceInformation(tenantName);
            foreach (var item in information)
            {
                Console.WriteLine(string.Format("{0} {1} {2} {3}", item.ContractName, item.InterfaceName, item.UrlSpecification, item.Vip));
            }
        }

        Console.ReadLine();
    }
}

What I'm after is returned as the item.Vip.

Note, obviously, that this will only work in the development fabric ... but that's what I was looking for here, anyway.

于 2011-07-18T14:23:32.540 に答える
0

使ってみましたか

RoleEnvironment.CurrentRoleInstance.InstanceEndpoints

私は自分のPCの後ろにいないので、atmはわかりませんが、すぐに再確認します. とにかく、各エンドポイントには、ポートも持つプロパティ IPEndPoint があります。パブリック エンドポイントも取得する場合 (現在のロール インスタンスに対して行うと思います)、そこからアドレスを取得できるはずです。

それが役に立てば幸い...

于 2011-07-18T05:07:19.180 に答える
0

81/82 などの「間違った」ポートの理由は、目的のポートがビジーであるためだと思います。

おそらく、ポート 80 をリッスンしている他のアプリがあるため、使用できません。また、エミュレーターの Azure コンピューティング インスタンスが十分に迅速にシャットダウンしないことを何度か見てきました。そのため、新しいインスタンスを開始すると、次のポートが取得されます。それを強制終了した場合は、少し待ってからもう一度開始します。ポート。

API 経由で公開されていないのはおそらくそのためです。また、テスト中は、他のアプリと競合していないことを確認し、コンピュート ノートが正常にシャットダウンしてポートが解放されるまでの時間を確保してください。

于 2011-07-18T08:29:04.137 に答える
0

dev ファブリック アセンブリを動作させることができなかった (API が変更されたようです) ため、"csrun /status" の出力を解析して、特定のロール名の IP アドレスを見つけることにしました。IP を取得するためのコードを次に示しますが、ポートを取得するには少し追加の作業を行う必要があります。

public static string GetEmulatorIPAddress(string roleName)
    {
        var psi = new ProcessStartInfo();
        psi.FileName = @"C:\Program Files\Microsoft SDKs\Windows Azure\Emulator\csrun.exe";
        psi.Arguments = "/status";
        psi.RedirectStandardOutput = true;
        psi.RedirectStandardError = true;
        psi.RedirectStandardInput = true;
        psi.UseShellExecute = false;
        psi.CreateNoWindow = true;

        StringBuilder sb = new StringBuilder();

        DataReceivedEventHandler errorHandler = (object sender, DataReceivedEventArgs e) =>
            {

            };

        string lastIPAddress = null;
        string foundIPAddress = null;

        DataReceivedEventHandler dataHandler = (object sender, DataReceivedEventArgs e) =>
        {
            string line = e.Data;
            if (line != null && foundIPAddress == null)
            {
                if (line.StartsWith("EndPoint: http://"))
                {
                    int ipStart = line.IndexOf("://") + "://".Length;
                    int ipEnd = line.IndexOf(":", ipStart);
                    lastIPAddress = line.Substring(ipStart, ipEnd - ipStart);
                }

                if (line.Trim() == roleName)
                {
                    foundIPAddress = lastIPAddress;
                }
            }
        };

        Process p = new Process();
        p.StartInfo = psi;
        p.ErrorDataReceived += errorHandler;
        p.OutputDataReceived += dataHandler;
        p.EnableRaisingEvents = true;
        p.Start();
        p.BeginOutputReadLine();
        p.BeginErrorReadLine();

        p.WaitForExit();

        return foundIPAddress;
    }
于 2014-04-17T16:05:43.763 に答える