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

时间:2015-03-02 11:11:07

标签: c# wcf http microsoft-sync-framework

我有一个由Sync Framework生成的WCF客户端/服务器架构。 出于某种原因,我必须将客户端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文件中执行此覆盖,但我不能。我能做到这一点似乎错过了足够的课程。互联网上的一些人遇到过这种问题,但从来没有这种架构和那种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);
    }
} 

如果有人找到答案,那个人将会得到我永恒的感激之情。

1 个答案:

答案 0 :(得分:0)

app.config中的

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

<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代理时触发。在另一个网络上没关系。

我正在研究这个问题,但如果你有一个想法,那么你将成为我的英雄。