2017-05-09 55 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