WCF从客户端向服务器发送int

我遇到了这个问题:

我有一个WCF服务,它公开了这个操作合同:

[OperationContract] void Index(int[] song, string fileName); 

在我的客户,我有:

 AudioDetectionServiceReference.AudioDetectionServiceClient client = new AudioDetectionServiceReference.AudioDetectionServiceClient(); client.Index(max.ToArray(), mp3Files[i]); 

其中max是2000个int值的数组,而mp3Files [i]是一个200个字符的字符串。

Web.config有这个:

                      

app.config有:

                    

现在是棘手的部分:

右键单击服务引用时,转到配置服务引用,有一个名为Collection type的选项。 如果我将集合类型设置为“Syste.Array”,我会收到错误

 The remote server returned an unexpected response: (400) Bad Request. 

使用堆栈跟踪:

  Server stack trace: at System.ServiceModel.Channels.HttpChannelUtilities.ValidateRequestReplyResponse(HttpWebRequest request, HttpWebResponse response, HttpChannelFactory factory, WebException responseException, ChannelBinding channelBinding) at System.ServiceModel.Channels.HttpChannelFactory.HttpRequestChannel.HttpChannelRequest.WaitForReply(TimeSpan timeout) at System.ServiceModel.Channels.RequestChannel.Request(Message message, TimeSpan timeout) at System.ServiceModel.Channels.ServiceChannel.Call(String action, Boolean oneway, ProxyOperationRuntime operation, Object[] ins, Object[] outs, TimeSpan timeout) at System.ServiceModel.Channels.ServiceChannelProxy.InvokeService(IMethodCallMessage methodCall, ProxyOperationRuntime operation) at System.ServiceModel.Channels.ServiceChannelProxy.Invoke(IMessage message) Exception rethrown at [0]: at System.Runtime.Remoting.Proxies.RealProxy.HandleReturnMessage(IMessage reqMsg, IMessage retMsg) at System.Runtime.Remoting.Proxies.RealProxy.PrivateInvoke(MessageData& msgData, Int32 type) at SqlTest.AudioDetectionServiceReference.IAudioDetectionService.Index(Int32[] song, String fileName) at SqlTest.AudioDetectionServiceReference.AudioDetectionServiceClient.Index(Int32[] song, String fileName) in blablabla\Service References\AudioDetectionServiceReference\Reference.cs:line 53 at SqlTest.Program.Main(String[] args) in blablabla\Program.cs:line 46 

当我将其更改为“System.Collection.Generic.List”时,错误会神奇地消失。

我的问题是: 为什么?

第二个问题:

为什么这样做?

 client.Index(max.Take(100).ToArray(), mp3Files[i]); 

使用相同的上下文(app.config,web.config,和上面相同的代码,选择System.Array)。

谢谢,Andrei Neagu

PS:我发布这个是因为我花了2天时间尝试更改绑定设置,更改消息大小,更改readerQuotas和其他内容的值,当我不得不做这个愚蠢的选择时。 所以我很生气,我想至少从中学到一些东西。

经过一番挖掘后,我就改变了:

的app.config

               

对于服务器,请查看basicHttpBinding部分没有名称的事实。 我认为如果此部分有名称,WCF生成的默认服务将忽略它。

            

而对于其他值,我在末尾添加了一个0(乘以10)。 增加它们我认为会让你更多地转移事件。 但最重要的是,basicHttpBinding没有名字。 如果它有一个名字,我认为它被忽略了。

我不会将其设置为已回答,因为问题是为什么System.Array抛出exception而System.Generic.List没有。