2015-03-02 49 views
1

我有一個由Sync Framework生成的WCF客戶端/服務器體系結構。 由於某些原因,我必須將客戶端的POST消息的HTTP版本從1.1更改爲1.0(因爲客戶端和服務器之間的代理服務器)[WCF] [SyncFramework]如何重寫GetWebRequest?

在鍵盤上敲了敲頭之後,我發現必須重寫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); 
    } 
} 

如果有人認爲作爲答案,那個人就會有我的感恩永恆。

回答

0

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的分塊信息=串流播放

但是等等!還有更多 !

現在仍有潛在的問題,作爲同步前進到〜14%:

(嚴重翻譯)壞SOAP ADRESS或動作。內部例外:404錯誤

此異常僅在通過squid代理時觸發。在另一個網絡上,它很好。

我正在研究這個問題,但如果你有一個想法,你將成爲我的英雄。

+0

這最後一個是通過更改隱藏在文件service.wsdl/xsd等中的url'localhost'來解決的......不要問爲什麼url是這樣的,而不是像.config中指定的那個。 。 – thi 2016-03-15 09:04:06