2017-05-09 30 views
2

我有一個將接收到的文件存儲在數據庫中的Web服務(WCF)。 當我把它從.NET 4.5的Web應用程序我只指定客戶端的Web.config文件:從桌面應用程序(.Net 2)調用WebService(WCF)時的消息大小

<bindings> 
    <basicHttpBinding> 
    <binding name="BasicHttpBinding_NameOfWS" 
      maxBufferSize="2147483647" 
      maxReceivedMessageSize="2147483647" /> 
    </basicHttpBinding> 
</bindings> 

因此允許客戶端發送大文件。

當我嘗試從我的.NET 2桌面應用程序調用它(是的,.NET 2)我收到錯誤:

HTTP 413: Request Entity Too Large 

但我沒有Web.config文件來配置,因爲它是不是一個Web應用程序。

我的app.config樣子:

<applicationSettings> 
    <NameOfProject.Properties.Settings> 
     <setting name="NameOfProject_NameOfWebReference_NameOfWS" 
      serializeAs="String"> 
      <value>http://myURL/NameOfWS.svc</value> 
     </setting> 
    </NameOfProject.Properties.Settings> 
</applicationSettings> 

而且NameOfWS.wsdl文件沒有MAXBUFFERSIZE或maxReceivedMessageSize參數。

我錯過了什麼?

在此先感謝。

+0

完成,不知道這個政策:) – Marta

回答

0

解決!

如果有人需要解決這樣的問題,我會發布如何使其工作。

Web.config文件在我的服務項目

<system.serviceModel> 
    <behaviors> 
     <serviceBehaviors> 
     <behavior name=""> 
      <serviceMetadata httpGetEnabled="true" httpsGetEnabled="true" /> 
      <serviceDebug includeExceptionDetailInFaults="false" /> 
     </behavior> 
     </serviceBehaviors> 
    </behaviors> 
    <serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true" /> 
    <bindings> 
     <basicHttpBinding> 
     <binding name="BasicHttpBinding_MyWCFInterface" maxBufferSize="2147483647" maxReceivedMessageSize="2147483647" /> 
     </basicHttpBinding> 
    </bindings> 
    <services> 
     <service name="MyProject.MyWCFClass" > 
     <endpoint address="" 
        binding="basicHttpBinding" 
        bindingConfiguration="BasicHttpBinding_MyWCFInterface" 
        contract="MyProject.MyWCFInterface"/> 
     </service> 
    </services> 
</system.serviceModel> 

在我的客戶端項目的App.config

<system.serviceModel> 
    <bindings> 
    <basicHttpBinding> 
      <binding name="BasicHttpBinding_MyWCFInterface" hostNameComparisonMode="StrongWildcard" maxBufferSize="2147483647" maxBufferPoolSize="2147483647" maxReceivedMessageSize="2147483647"> 
     <readerQuotas maxDepth="2147483647" maxStringContentLength="2147483647" maxArrayLength="2147483647" maxBytesPerRead="2147483647" maxNameTableCharCount="2147483647" /> 
     </binding> 
    </basicHttpBinding> 
    </bindings> 
    <client> 
    <endpoint address="http://localhost:myPort/MyService.svc" 
       binding="basicHttpBinding" 
       bindingConfiguration="BasicHttpBinding_MyWCFInterface" 
       contract="NameOfCreatedService.MyWCFInterface" 
       name="BasicHttpBinding_MyWCFInterface" /> 
    </client> 
</system.serviceModel> 

什麼我不知道,並已最後一步,是複製我的客戶端解決方案的主項目的App.config中的這個App.config配置,如果沒有配置不加載在s tartup並且不能處理郵件大小配置。

我希望它可以幫助任何人。

感謝那些花了一些時間處理這個問題的人。

1

對於app.config綁定配置示例

這些方法中的一些請嘗試;

<binding name="bindingName" closeTimeout="00:20:00" openTimeout="00:20:00" receiveTimeout="01:00:00" sendTimeout="01:00:00" hostNameComparisonMode="StrongWildcard" maxBufferSize="2147483647" maxBufferPoolSize="2147483647" maxReceivedMessageSize="2147483647"> 
     <readerQuotas maxDepth="2147483647" maxStringContentLength="2147483647" maxArrayLength="2147483647" maxBytesPerRead="2147483647" maxNameTableCharCount="2147483647" /> 
     <security mode="Transport" /> 
    </binding> 
+0

它不起作用,我剛剛看到,BasicHttpBinding的作品,因爲.Net 3.0 ... – Marta

0

寫上您的.NET 2的app.config必須收到文件,但我建議你複製.NET 4的app.config標籤.NET 2的app.config它必須努力

<system.serviceModel> 
 
    <bindings> 
 
    <basicHttpBinding> 
 
     <binding maxReceivedMessageSize="10485760"> 
 
     <readerQuotas ... /> 
 
     </binding> 
 
    </basicHttpBinding> 
 
    </bindings> 
 
</system.serviceModel>

+0

我試過這個配置,但它不工作,我剛剛看到BasicHttpBinding從.Net 3.0開始工作:( – Marta