3

ServiceHost オブジェクトでホストされている WCF サービスがあります。ServiceHost は、Azure Worker ロールの OnStart メソッドで作成されます。コードは次のとおりです。

        ServiceBusEnvironment.SystemConnectivity.Mode = ConnectivityMode.Http;

        Uri baseAddress = ServiceBusEnvironment.CreateServiceUri("http", "my_sb", "SimpleService");

        host = new ServiceHost(typeof(SimpleService1.Service1), baseAddress);

        BasicHttpRelayBinding binding = new BasicHttpRelayBinding(EndToEndBasicHttpSecurityMode.None, RelayClientAuthenticationType.None);
        binding.OpenTimeout = new TimeSpan(1, 1, 0);
        binding.ReceiveTimeout = new TimeSpan(1, 10, 0);
        binding.SendTimeout = new TimeSpan(1, 10, 0);
        binding.MaxReceivedMessageSize = 73400320;
        XmlDictionaryReaderQuotas readerQuotas = new XmlDictionaryReaderQuotas();
        readerQuotas.MaxArrayLength = 73400320;
        binding.ReaderQuotas = readerQuotas;

        TransportClientEndpointBehavior sharedSecretServiceBusCredential = new TransportClientEndpointBehavior();
        sharedSecretServiceBusCredential.CredentialType = TransportClientCredentialType.SharedSecret;

        sharedSecretServiceBusCredential.Credentials.SharedSecret.IssuerName = "owner";
        sharedSecretServiceBusCredential.Credentials.SharedSecret.IssuerSecret = "blablablabla==";


        ContractDescription contractDescription = ContractDescription.GetContract(typeof(SimpleService1.IService1), typeof(SimpleService1.Service1));
        ServiceEndpoint serviceEndPoint = new ServiceEndpoint(contractDescription);
        serviceEndPoint.Address = new EndpointAddress(baseAddress);
        serviceEndPoint.Binding = binding;

        IEndpointBehavior serviceRegistrySettings = new ServiceRegistrySettings(DiscoveryType.Public);

        serviceEndPoint.Behaviors.Add(serviceRegistrySettings);
        serviceEndPoint.Behaviors.Add(sharedSecretServiceBusCredential);


        host.Description.Endpoints.Add(serviceEndPoint);

        try
        {

            host.Open();

        }

        catch (Exception ex)
        {

            Trace.WriteLine(ex.Message, "Error");

            throw;

        }

        Trace.WriteLine("SimpleService1 running...");

クライアント側のバインディング構成は次のとおりです。

        <basicHttpBinding>
          <binding name="FileTransferBinding" closeTimeout="00:10:00" openTimeout="00:10:00" receiveTimeout="00:10:00" sendTimeout="00:10:00" maxReceivedMessageSize="73400320">
            <readerQuotas maxArrayLength="73400320"/>
            <security mode="None"/>
          </binding>
        </basicHttpBinding>

<endpoint address="http://my_sb.servicebus.windows.net/simpleservice" binding="basicHttpBinding" bindingConfiguration="FileTransferBinding" contract="Service1reference.IService1" name="FileTransferBinding" behaviorConfiguration="sbBehavior"/>

問題は、サービスへの 1 回の呼び出しに 1 分以上かかる場合、クライアントが次の例外を受け取ることです。

The content type application/xml; charset=utf-8 of the response message does not match the content type of the binding (text/xml; charset=utf-8). If using a custom encoder, be sure that the IsContentTypeSupported method is implemented properly

バインディングを netTcpRelayBinding に変更すると、すべて正常に動作します。

4

1 に答える 1

3

これは、接続が 1 分以上アイドル状態の場合、Windows Azure ロード バランサーがユーザーを切断するためです。

最善の策は、WCF コールバックを使用することです。これにより、サーバーからクライアントへの呼び出しが実行され、長時間実行される操作が完了したことが通知されます。これを行う方法の詳細については、このブログをご覧ください [ WCF Callbacks

于 2011-09-21T07:37:18.313 に答える