我使用JQuery .AJAX调用我的WCF Web服务并传递要处理的项集合。大部分时间它工作正常,但是当我在POST时收集大量项目时,我立即得到错误400.
这是jQuery代码:
// Get the selected items
var oAssayOrderListSelected = jQuery.grep(oAssayOrderList, function (element, index) {
return element.SelectedForProcessing == true;
});
DataAsJson = { "SelectedItems": oAssayOrderListSelected };
var DataAsJsonString = JSON.stringify(DataAsJson);
// Call the web service to Process the Assays
$.ajax({
cache: false,
url: "AssayControlWS.svc/ProcessOrdersForAssays",
type: "POST",
async: true,
dataType: "json",
data: DataAsJsonString,
contentType: "application/json; charset=utf-8",
success: function (processingResults) {
// Update the results table with the result information
if (processingResults.Status == "Success") {
}
else {
// insert error message handler!!!!!
}
},
以下是要调用的Web服务方法的声明:
[WebInvoke(Method = "POST", BodyStyle = WebMessageBodyStyle.WrappedRequest, ResponseFormat = WebMessageFormat.Json, RequestFormat = WebMessageFormat.Json)]
public ReleaseResult ProcessOrdersForAssays(List<AssayGroupOrOrderSummary> SelectedItems)
{ ... }
以下是该服务的web.config条目。如图所示,我已经从默认值
大大增加了缓冲区大小 <service name="AssayControl_Web.AssayControlWS" behaviorConfiguration="metadataAndDebug">
<endpoint address="" behaviorConfiguration="AssayControl_Web.AssayControlWSAspNetAjaxBehavior"
binding="webHttpBinding" contract="AssayControl_Web.AssayControlWS" bindingName="AssayControl_Web.AssayControlWS" />
</service>
<behaviors>
<endpointBehaviors>
<serviceBehaviors>
<behavior name="metadataAndDebug">
<serviceMetadata httpGetEnabled="true" httpGetUrl=""/>
<serviceDebug httpHelpPageEnabled="true" includeExceptionDetailInFaults="true" />
</behavior>
</serviceBehaviors>
</endpointBehaviors>
</behaviors>
<webHttpBinding>
<binding name="AssayControl_Web.AssayControlWS" maxBufferSize="200000000"
maxBufferPoolSize="200000000" maxReceivedMessageSize="200000000"
transferMode="Buffered" />
</webHttpBinding>
有关导致此400错误的原因的任何想法?
===================问题解决了========================== =====
添加WCF日志记录后,我发现问题是Web服务使用默认值65536作为maxReceivedMessageSize。尽管我将此值设置为更高的值。
此外,搜索显示其他几个人遇到了忽略maxReceivedMessageSize的问题。我解决问题的方法是从webHttpBinding中删除Name属性,使该设置成为所有webHttpBinding的默认设置。然后从服务端点删除BindingName属性,以便它使用默认绑定。
以下是使用相同修补程序http://social.msdn.microsoft.com/Forums/vstudio/en-US/985e039f-1610-4f62-9c3d-51ec7e1b1673/problem-with-maxreceivedmessagesize-webconfig-ignored解决此问题的其他报告的链接。也许这与.net 4.0及更高版本使用的新简化绑定方法有关。