开发者

WCF service on ServiceBus fails if call longer than 1 minute

I have a WCF Service that is hosted in a ServiceHost object. The ServiceHost is created on the OnStart method of an Azure Worker Role. Here is the code:

        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...");

and the binding configuration on the client side is:

        <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>
开发者_StackOverflow中文版

and

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

The problem is that if one call to the service takes longer than 1 minute, the client receives this exception:

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

If I change the binding to a netTcpRelayBinding everything works fine.


This is because the Windows Azure load-balancer disconnects you if the connection is idle for more than a minute.

Your best bet is to use a WCF callback. This will execute a call from the server to the client to let it know that the long-running operation has completed. For more on how to do this have a look at this blog [WCF Callbacks

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜