2017-12-13 5 views
0

C#でAzure Cloud Service TCPリスナーを作成しましたが、今はローカルでデバッグしようとしています。以下のサービス定義は興味のあるポートを公開していますが、ローカルで実行されている場合、アドレスは同じネットワーク上の他のデバイスからは見えないlocalhostにバインドされています。Azure Compute Emulatorでポートを外部に公開する

<?xml version="1.0" encoding="utf-8"?> 
<ServiceDefinition name="Foo.Listener.Azure" xmlns="http://schemas.microsoft.com/ServiceHosting/2008/10/ServiceDefinition" schemaVersion="2015-04.2.6"> 
    <WorkerRole name="Foo.Listener" vmsize="Small"> 
    <ConfigurationSettings> 
     <Setting name="Microsoft.WindowsAzure.Plugins.Diagnostics.ConnectionString" /> 
    </ConfigurationSettings> 
    <Endpoints> 
     <InputEndpoint name="Foo Protocol" protocol="tcp" port="9100" localPort="9100" /> 
    </Endpoints> 
    </WorkerRole> 
</ServiceDefinition> 

私は、次のコマンドを使用して、ポートプロキシを追加しようとしている:

netsh interface portproxy add v4tov4 listenport=9100 connectaddress=localhost connectport=9100 protocol=tcp 

はしかし、コンピュート・エミュレータは、私がこれを行う際に、ポート番号9100が使用中であると考えているようだ、それは9101を選びます代わりに。ワーカー・ロールをローカルで実行し、外部接続を受け入れる方法を教えてください。

答えて

0

私は、この作業を、作業者の役割でチェックを追加することによって行うことができました。それはかなりではありません。私はむしろ、コードを通じてではなく、設定を通してこれをやっていますが、私の解決策はここにあります。

IEnumerable<IPEndPoint> endpoints; 

if (RoleEnvironment.IsEmulated) 
{ 
    endpoints = Dns.GetHostEntry(Dns.GetHostName()) 
     .AddressList 
     .Select(address => new IPEndPoint(address, 9100)); 
} 
else 
{ 
    endpoints = RoleEnvironment.CurrentRoleInstance 
     .InstanceEndpoints 
     .Select(endpoint => endpoint.Value.IPEndpoint); 
} 
関連する問題