1

WCF サービスを作成し、worker ロールを使用してクラウドでホストしました。残念ながら、worker ロール サービスに接続しようとすると、「ホスト 3a5c0cdffcf04d069dbced5e590bca70.cloudapp.net の DNS エントリが存在しません」というメッセージとともに例外が発生します。3a5c0cdffcf04d069dbced5e590bca70.cloudapp.net は、Azure ステージング環境にデプロイされた worker ロールのアドレスです。workerrole.cs には、WCF サービスを公開する次のコードがあります。

    public override void Run()
    {
        using (ServiceHost host = new ServiceHost(typeof(MyService)))
        {
            string ip = RoleEnvironment.CurrentRoleInstance.InstanceEndpoints["tcppoint"].IPEndpoint.Address.ToString();
            int tcpport = RoleEnvironment.CurrentRoleInstance.InstanceEndpoints["tcppoint"].IPEndpoint.Port;
            int mexport = RoleEnvironment.CurrentRoleInstance.InstanceEndpoints["mexinput"].IPEndpoint.Port;

            // Add a metadatabehavior for client proxy generation
            // The metadata is exposed via net.tcp
            ServiceMetadataBehavior metadatabehavior = new ServiceMetadataBehavior();
            host.Description.Behaviors.Add(metadatabehavior);
            Binding mexBinding = MetadataExchangeBindings.CreateMexTcpBinding();
            string mexlistenurl = string.Format("net.tcp://{0}:{1}/MyServiceMetaDataEndpoint", ip, mexport);
            string mexendpointurl = string.Format("net.tcp://{0}:{1}/MyServiceMetaDataEndpoint", RoleEnvironment.GetConfigurationSettingValue("Domain"), 8001);
            host.AddServiceEndpoint(typeof(IMetadataExchange), mexBinding, mexendpointurl, new Uri(mexlistenurl));

            // Add the endpoint for MyService
            string listenurl = string.Format("net.tcp://{0}:{1}/MyServiceEndpoint", ip, tcpport);
            string endpointurl = string.Format("net.tcp://{0}:{1}/MyServiceEndpoint", RoleEnvironment.GetConfigurationSettingValue("Domain"), 9001);
            host.AddServiceEndpoint(typeof(IMyService), new NetTcpBinding(SecurityMode.None), endpointurl, new Uri(listenurl));
            host.Open();

            while (true)
            {
                Thread.Sleep(100000);
                Trace.WriteLine("Working", "Information");
            }
        }
    } 

tcppoint と mexinput は、ポート 8001 と 9001 で構成されます。また、ドメインはワーカー ロールの展開 URL で構成されます:3a5c0cdffcf04d069dbced5e590bca70.cloudapp.net

クライアント部分 (コンソール アプリ) では、app.config で次の構成を使用しています。

    <bindings>
        <netTcpBinding>
            <binding name="NetTcpBinding_IMyService" closeTimeout="00:01:00"
                openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:01:00"
                transactionFlow="false" transferMode="Buffered" transactionProtocol="OleTransactions"
                hostNameComparisonMode="StrongWildcard" listenBacklog="10"
                maxBufferPoolSize="524288" maxBufferSize="65536" maxConnections="10"
                maxReceivedMessageSize="65536">
                <readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="16384"
                    maxBytesPerRead="4096" maxNameTableCharCount="16384" />
                <reliableSession ordered="true" inactivityTimeout="00:50:00"
                    enabled="false" />
                <security mode="None">
                    <transport clientCredentialType="Windows" protectionLevel="EncryptAndSign" />
                    <message clientCredentialType="Windows" />
                </security>
            </binding>
        </netTcpBinding>

    </bindings>
    <client>
      <endpoint address="httpp:\\3a5c0cdffcf04d069dbced5e590bca70.cloudapp.net:9001/MyServiceEndpoint" binding="netTcpBinding"
         bindingConfiguration="NetTcpBinding_IMyService" contract="ServiceReference1.IMyService"
         name="NetTcpBinding_IMyService" />
    </client>

  <behaviors>
    <serviceBehaviors>
      <behavior name="behave">
        <serviceMetadata httpGetEnabled="false"/>
      </behavior>
    </serviceBehaviors>
  </behaviors>   

</system.serviceModel>
<system.net>
  <defaultProxy useDefaultCredentials="true">
  <proxy autoDetect="False" usesystemdefault="False" bypassonlocal="True" />
</defaultProxy>

次のコードは、msdn でバックグラウンドとして使用できるサンプル コードを使用して構築されています。ローカルでは問題なく動作しています。残念ながら、クラウドにデプロイすると例外が発生します。さらに、URL の代わりに仮想 IP を使用すると、接続タイムアウトが発生し、リモート マシンが応答しませんでした。

4

2 に答える 2

0

net.tcp (TCP) でリッスンするようにサービスをセットアップし、クライアントは http バインディングを使用しているようです。ローカルでも機能するとは思いません。ServiceDefinition でポート 9000 を実際に開いていると仮定します。負荷分散されたエンドポイントになることを忘れないでください。デプロイ内 (ロール間) からこのインスタンスに通信しようとしていますか、それともクラウドの外部から通信しようとしていますか?

ホストとクライアント (ロール内で通信する場合) をコードでセットアップする方がはるかに簡単であることがわかりました。これを試して:

http://dunnry.com/blog/2010/05/28/HostingWCFInWindowsAzure.aspx

展開外のクライアントからサービスをヒットしようとしている場合、これは引き続き適用されますが、クライアントの構築部分が対象です。ServiceDefinition で定義された外部 DNS 名とポートを使用する必要があります。

また、ロールの準備が整う前にエンドポイントにアクセスしようとすると、DNS エラーが発生することもありました。DNS の伝播には少し時間がかかる場合があり、偽の DNS エントリをキャッシュしないように、準備が整うまで DNS を解決しないようにしてください。ただし、その DNS 名を VIP アドレスに解決できる場合、それは問題ではありません。

于 2011-08-18T17:07:33.500 に答える