C# WCF: WCF Service returning a (404) Bad Request when sending an array of items

风流意气都作罢 提交于 2019-12-19 09:45:24

问题


I am trying to send an array of about 50 elements to a WCF service method, but I'm always receiving a (404) Bad Request error.

I think that it has to do with the message size or something like that, because if I send an empty array it works.

I did some research and added some stuff in the web.config of the WCF but I still can't manage to get this to work.

Can anyone please provide some additional information as to how I can maybe increase the size of the message I can send?


[UPDATE] Solution:

Solution


回答1:


Stupid, stupid me :(

The thing is that I was creating the binding configuration in the web.config like such:

<bindings>
    <wsHttpBinding>
        <binding name="netTcpBindingConfig" closeTimeout="00:10:00" openTimeout="00:10:00" receiveTimeout="00:10:00" sendTimeout="00:10:00" transactionFlow="false" hostNameComparisonMode="StrongWildcard"  maxBufferPoolSize="524288" maxReceivedMessageSize="6000000">
            <readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="6000000" maxBytesPerRead="4096" maxNameTableCharCount="16384" />
        </binding>
    </wsHttpBinding>
</bindings>

But then I was not applying the configuration to the endpoint! So, I had to add this to the endpoint tag:

bindingConfiguration="netTcpBindingConfig"

Now it works like a charm.




回答2:


It's an obvious one but have you tried setting MaxReceivedMessageSize to 65536 and seeing if it still fails?




回答3:


Your service host should be configured to recieve large set of data, if not, it is either dropped at service level.

  • Add reference to System.Runtime.Serialization.
  • When creating the binding set the message size:

    
    return new NetTcpBinding(SecurityMode.None, true)  
    {  
        MaxReceivedMessageSize = 99999999,  
        ReaderQuotas = { MaxArrayLength = 99999999 }  
    };
    
    


来源:https://stackoverflow.com/questions/740039/c-sharp-wcf-wcf-service-returning-a-404-bad-request-when-sending-an-array-of

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!