Set KeepAlive in WCF Data Services

I am using a Microsoft opt-out product called WCF Data Services. I hope I can help here.

I am trying to configure my services to run in a load balancer (F5). The problem I ran into I also had with my regular WCF services. Basically, F5 sees the connection as a "permanent" connection.

To fix this with my WCF services, I can set the KeepAliveEnabled flag to false like this:

var endpointAddress = new EndpointAddress(new Uri("http://someAdrs/MyWcfService.svc"));
MyWcfClient client = new MyWcfClient (new BasicHttpBinding(), endpointAddress);
var customBinding = new CustomBinding(client.Endpoint.Binding);
var transportElement = customBinding.Elements.Find<HttpTransportBindingElement>();

transportElement.KeepAliveEnabled = false;

client.Endpoint.Binding = customBinding;

      

As I said, this works great for my WCF service. But I can't seem to find a way to set this up with a WCF Data Services client. (The client does not have an Endpoint variable.)

Does anyone have an idea on how to set KeepAlive to false for the Wcf data services client?

Update:

I've tried this:

entities.SendingRequest2 += EntitiesOnSendingRequest2;

private static void EntitiesOnSendingRequest2(object sender, 
    SendingRequest2EventArgs sendingRequest2EventArgs)
{
    sendingRequest2EventArgs.RequestMessage.SetHeader("Keep-Alive", "false");
}

      

But it did not help.

Update II:

I tried this in "EntitiesOnSendingRequest2":

sendingRequest2EventArgs.RequestMessage.SetHeader("Connection", "close");

      

But I got the error because the Connection header is limited.

+3


source to share


1 answer


I thought.

There is an event called "SendingRequest" that you can subscribe to. (This is deprecated, but it doesn't matter since Wcf data services are dead to Microsoft. It will never be removed due to Microsoft's brief attention these days.)

This event will allow you to receive the WebRequest, which can be passed to the HttpWebRequest.



Then it's as simple as setting KeepAlive = false;

entities.SendingRequest += EntitiesOnSendingRequest;


private static void EntitiesOnSendingRequest(object sender, 
      SendingRequestEventArgs sendingRequestEventArgs)
{
    var webRequest = ((HttpWebRequest) sendingRequestEventArgs.Request);
    webRequest.KeepAlive = false;
}

      

0


source







All Articles