【问题标题】:[WCF][SyncFramework] How to override GetWebRequest?[WCF][SyncFramework] 如何覆盖 GetWebRequest?
【发布时间】:2015-03-02 11:11:06
【问题描述】:

我有一个由 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);
    }
} 

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

【问题讨论】:

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


    【解决方案1】:
    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 代理时触发。在另一个网络上没问题。

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

    【讨论】:

    • 这最后一个是通过更改隐藏在文件 service.wsdl/xsd 等中的 url 'localhost' 来解决的......不要问为什么 url 是这样的,而不是像在.config...
    猜你喜欢
    • 2011-01-30
    • 2013-04-13
    • 1970-01-01
    • 1970-01-01
    • 2021-06-26
    • 2015-09-04
    • 1970-01-01
    • 1970-01-01
    • 2015-09-09
    相关资源
    最近更新 更多