Search code examples
c#wcfhttpmicrosoft-sync-framework

[WCF][SyncFramework] How to override GetWebRequest?


I have a WCF client/server architecture generated by Sync Framework. For some reason, I must change the HTTP version of the client's POST messages from 1.1 to 1.0 (because of the proxy between the client and server)

After banging my head on the keyboard I found that I have 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;
}

It seems that I must do this override in the generated Reference.cs file, BUT I can't. There seems to miss the adequate class were I can do that. Some people on the internet have had that kind of problem, but never with this architecture and that kind of Reference.cs file.

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);
    }
} 

If anybody finds as answer to this, that person will have my eternal gratitude.


Solution

  • 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.