[WCF][SyncFramework] 如何覆盖 GetWebRequest?

[WCF][SyncFramework] How to override GetWebRequest?

我有一个由 Sync Framework 生成的 WCF client/server 架构。 出于某种原因,我必须将客户端 POST 消息的 HTTP 版本从 1.1 更改为 1.0(因为客户端和服务器之间的代理)

在敲击键盘后,我发现我必须覆盖 GetWebRequest 才能更改我想要的有关 HTTP 协议的任何内容:

protected override WebRequest GetWebRequest(Uri uri)
{
    HttpWebRequest webRequest = (HttpWebRequest) base.GetWebRequest(uri);

    webRequest.KeepAlive = false;
    webRequest.ProtocolVersion=HttpVersion.Version10;
    return webRequest;
}

看来我必须在生成的 Reference.cs 文件中执行此覆盖,但我不能。似乎错过了足够的 class 我可以做到这一点。互联网上有些人遇到过这种问题,但从来没有遇到过这种架构和那种 Reference.cs 文件。

这是 Reference.cs 代码:

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

如果有人找到答案,我将永远感激他。

transferMode=StreamedResponse app.config 帮助我解决了这个问题。

<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 代理 3.1.20 不喜欢由 transferMode=Streamed 引起的分块消息。

但是等等!还有更多 !

现在还有一个潜在的问题,因为同步达到了 ~14% :

(翻译错误)错误的 SOAP 地址或操作。内部异常:404 错误

此异常仅在通过 squid 代理时触发。在另一个网络上没问题。

我正在解决这个问题,但如果你有想法,你就是我的英雄。