none
How to override GetWebRequest? RRS feed

  • Question

  • Greetings,

    I have a WCF client/server architecture for synchronization purpose (SQL Server <-> SQL CE on WPF). 
    Because of the deployment environment (HTTP 1.0 proxy between client and server), I must change the HTTP version of the client's POST messages from 1.1 to 1.0 

    It seems that the only way is to override GetWebRequest to change anything I want concerning the HTTP protocol :

    protected override WebRequest GetWebRequest(Uri uri)
    {
        HttpWebRequest webRequest = (HttpWebRequest) base.GetWebRequest(uri);
    
        webRequest.KeepAlive = false;
        webRequest.ProtocolVersion=HttpVersion.Version10;
        return webRequest;
    }


    In a perfect world this override can be done by some kind of derivation of a class generated by the service reference, BUT I can't. There seems to miss the adequate class were I can place that code. Some people on the internet have had that kind of problem, but never with Sync Framework and that kind of Reference.cs file. 
    How can I do that ?

    Here's the Reference.cs code :

    [System.CodeDom.Compiler.GeneratedCodeAttribute("System.ServiceModel", "4.0.0.0")]
    [System.ServiceModel.ServiceContractAttribute(ConfigurationName = "VinciWCFRef.ISyncVinciSyncContract")]
    public interface ISyncVinciSyncContract
    {
        [System.ServiceModel.OperationContractAttribute(Action = "http://tempuri.org/ISyncVinciSyncContract/ApplyChanges", ReplyAction = "http://tempuri.org/ISyncVinciSyncContract/ApplyChangesResponse")]
        [System.ServiceModel.XmlSerializerFormatAttribute(SupportFaults = true)]
        SyncContext ApplyChanges(SyncGroupMetadata groupMetadata, System.Data.DataSet dataSet, SyncSession syncSession);
    
        [System.ServiceModel.OperationContractAttribute(Action = "http://tempuri.org/ISyncVinciSyncContract/GetChanges", ReplyAction = "http://tempuri.org/ISyncVinciSyncContract/GetChangesResponse")]
        [System.ServiceModel.XmlSerializerFormatAttribute(SupportFaults = true)]
        SyncContext GetChanges(SyncGroupMetadata groupMetadata, SyncSession syncSession);
    
        [System.ServiceModel.OperationContractAttribute(Action = "http://tempuri.org/ISyncVinciSyncContract/GetSchema", ReplyAction = "http://tempuri.org/ISyncVinciSyncContract/GetSchemaResponse")]
        [System.ServiceModel.XmlSerializerFormatAttribute(SupportFaults = true)]
        SyncSchema GetSchema(string[] tableNames, SyncSession syncSession);
    
        [System.ServiceModel.OperationContractAttribute(Action = "http://tempuri.org/ISyncVinciSyncContract/GetServerInfo", ReplyAction = "http://tempuri.org/ISyncVinciSyncContract/GetServerInfoResponse")]
        [System.ServiceModel.XmlSerializerFormatAttribute(SupportFaults = true)]
        SyncServerInfo GetServerInfo(SyncSession syncSession);
    
        [System.ServiceModel.OperationContractAttribute(Action = "http://tempuri.org/ISyncVinciSyncContract/GetServerChanges", ReplyAction = "http://tempuri.org/ISyncVinciSyncContract/GetServerChangesResponse")]
        [System.ServiceModel.XmlSerializerFormatAttribute(SupportFaults = true)]
        string[] GetServerChanges(SyncGroupMetadata groupMetadata, SyncSession syncSession);
    
        [System.ServiceModel.OperationContractAttribute(Action = "http://tempuri.org/ISyncVinciSyncContract/Genere_ID_Synchro", ReplyAction = "http://tempuri.org/ISyncVinciSyncContract/Genere_ID_SynchroResponse")]
        [System.ServiceModel.XmlSerializerFormatAttribute(SupportFaults = true)]
        string[] Genere_ID_Synchro(SyncGroupMetadata groupMetadata, SyncSession syncSession);
    
        [System.ServiceModel.OperationContractAttribute(Action = "http://tempuri.org/ISyncVinciSyncContract/TestConnect", ReplyAction = "http://tempuri.org/ISyncVinciSyncContract/TestConnectResponse")]
        [System.ServiceModel.XmlSerializerFormatAttribute(SupportFaults = true)]
        string[] TestConnect(SyncGroupMetadata groupMetadata, SyncSession syncSession);
    }
    
    [System.CodeDom.Compiler.GeneratedCodeAttribute("System.ServiceModel", "4.0.0.0")]
    public interface ISyncVinciSyncContractChannel : Vinci.VinciWCFRef.ISyncVinciSyncContract, System.ServiceModel.IClientChannel
    {}
    
    [System.Diagnostics.DebuggerStepThroughAttribute()]
    [System.CodeDom.Compiler.GeneratedCodeAttribute("System.ServiceModel", "4.0.0.0")]
    public partial class SyncVinciSyncContractClient : System.ServiceModel.ClientBase<Vinci.VinciWCFRef.ISyncVinciSyncContract>, Vinci.VinciWCFRef.ISyncVinciSyncContract
    {
        public SyncVinciSyncContractClient(){}
    
        public SyncVinciSyncContractClient(string endpointConfigurationName) :
            base(endpointConfigurationName){}
    
        public SyncVinciSyncContractClient(string endpointConfigurationName, string remoteAddress) :
            base(endpointConfigurationName, remoteAddress)
        {
        }
    
        public SyncVinciSyncContractClient(string endpointConfigurationName, System.ServiceModel.EndpointAddress remoteAddress) :
            base(endpointConfigurationName, remoteAddress){}
    
        public SyncVinciSyncContractClient(System.ServiceModel.Channels.Binding binding, System.ServiceModel.EndpointAddress remoteAddress) :
            base(binding, remoteAddress){}
    
        public SyncContext ApplyChanges(SyncGroupMetadata groupMetadata, System.Data.DataSet dataSet, SyncSession syncSession)
        {
            return base.Channel.ApplyChanges(groupMetadata, dataSet, syncSession);
        }
    
        public SyncContext GetChanges(SyncGroupMetadata groupMetadata, SyncSession syncSession)
        {
            return base.Channel.GetChanges(groupMetadata, syncSession);
        }
    
        public SyncSchema GetSchema(string[] tableNames, SyncSession syncSession)
        {
            return base.Channel.GetSchema(tableNames, syncSession);
        }
    
        public SyncServerInfo GetServerInfo(SyncSession syncSession)
        {
            return base.Channel.GetServerInfo(syncSession);
        }
    
        public string[] GetServerChanges(SyncGroupMetadata groupMetadata, SyncSession syncSession)
        {
            return base.Channel.GetServerChanges(groupMetadata, syncSession);
        }
    
        public string[] Genere_ID_Synchro(SyncGroupMetadata groupMetadata, SyncSession syncSession)
        {
            return base.Channel.Genere_ID_Synchro(groupMetadata, syncSession);
        }
    
        public string[] TestConnect(SyncGroupMetadata groupMetadata, SyncSession syncSession)
        {
            return base.Channel.TestConnect(groupMetadata, syncSession);
        }
    } 


    Thanks for your help
    • Edited by Exo-Charbo Tuesday, March 3, 2015 2:45 PM
    Tuesday, March 3, 2015 2:44 PM

Answers

  • transferMode=StreamedResponse in the app.config helped me for this issue.

    <bindings>
          <basicHttpBinding>
            <binding name="basicHttpBinding" closeTimeout="00:45:00" openTimeout="00:45:00"
              receiveTimeout="00:45:00" sendTimeout="00:45:00" allowCookies="false"
              bypassProxyOnLocal="false" hostNameComparisonMode="StrongWildcard"
              maxBufferSize="2147483647" maxBufferPoolSize="2147483647" maxReceivedMessageSize="2147483647"
              messageEncoding="Text" textEncoding="utf-8" transferMode="StreamedResponse"
              useDefaultWebProxy="true">
              <readerQuotas maxDepth="32" maxStringContentLength="2147483647"
                maxArrayLength="2147483647" maxBytesPerRead="2147483647" maxNameTableCharCount="2147483647" />
              <security mode="None">
                <transport clientCredentialType="None" realm="" />
              </security>
            </binding>
          </basicHttpBinding>
        </bindings>

    Squid proxy 3.1.20 didn't like the chunked messages caused by the transferMode=Streamed .

    But wait ! There's more !

    Now there is still an underlying problem, as the synchronization goes to ~14% :

    (badly translated) bad SOAP adress or action. Inner exception : 404 error

    this exception fires only when going through the squid proxy. On another network it's fine.

    I'm working on that problem, but if you have an idea you'll be my hero.


    • Edited by Exo-Charbo Thursday, March 5, 2015 8:45 AM
    • Marked as answer by Exo-Charbo Thursday, March 5, 2015 8:47 AM
    Thursday, March 5, 2015 8:33 AM