处理大型对象图时客户端出现模糊的WCF错误

处理大型对象图时客户端出现模糊的WCF错误,wcf,Wcf,我正在从SharePoint站点调用WCF服务,在返回相对较大的对象图时,客户端出现错误,并显示以下详细信息 在调试服务时,我可以看到is正确地构造了对象,并且该方法正确地返回了最终的对象(包含其他对象的列表)。但我在客户端的服务方法调用中遇到异常 这种服务/方法在大多数情况下都很有效。以下是服务配置(对格式错误表示歉意) 服务配置: <system.serviceModel> <services> <service behaviorConfiguration="S

我正在从SharePoint站点调用WCF服务,在返回相对较大的对象图时,客户端出现错误,并显示以下详细信息

在调试服务时,我可以看到is正确地构造了对象,并且该方法正确地返回了最终的对象(包含其他对象的列表)。但我在客户端的服务方法调用中遇到异常

这种服务/方法在大多数情况下都很有效。以下是服务配置(对格式错误表示歉意)

服务配置:

<system.serviceModel>
<services>
<service behaviorConfiguration="StandardServiceBehaviour" name="Thd.K2.Web.DataServicesLibrary.Common.Services.AdminService">

            <endpoint address="soap" binding="basicHttpBinding" name="AdminService" contract="Thd.K2.Web.DataServicesLibrary.Common.Interfaces.IAdminService" />
            <endpoint address="mex" binding="mexHttpBinding" name="Metadata" contract="IMetadataExchange" kind="mexEndpoint" endpointConfiguration="" />
        </service>
</services>
<behaviors>
    <serviceBehaviors>
          <behavior name="StandardServiceBehaviour">
                  <serviceMetadata httpsGetEnabled="false" />
                  <serviceDebug includeExceptionDetailInFaults="true" />
            </behavior>                
        </serviceBehaviors>
    </behaviors>
    <bindings>
        <basicHttpBinding>
            <binding name="customBinding" hostNameComparisonMode="StrongWildcard" receiveTimeout="00:10:00" sendTimeout="00:10:00" openTimeout="00:10:00" closeTimeout="00:10:00" maxReceivedMessageSize="1000000" maxBufferSize="1000000" maxBufferPoolSize="1000000" transferMode="Buffered" messageEncoding="Text" textEncoding="utf-8" bypassProxyOnLocal="false" useDefaultWebProxy="true">
                <readerQuotas maxDepth="2147483647" maxStringContentLength="214748364" maxArrayLength="2147483647" maxBytesPerRead="2147483647" maxNameTableCharCount="2147483647" />
                <security mode="Transport" />
            </binding>
        </basicHttpBinding>
        <webHttpBinding>
          <binding name="webBinding" bypassProxyOnLocal="true" useDefaultWebProxy="false" hostNameComparisonMode="WeakWildcard" sendTimeout="00:05:00" openTimeout="00:05:00" receiveTimeout="00:05:00" maxReceivedMessageSize="2147483647" maxBufferSize="2147483647" maxBufferPoolSize="2147483647">
            <readerQuotas maxArrayLength="2147483647" maxStringContentLength="2147483647" />
            <security mode="Transport">
            </security>
          </binding>
        </webHttpBinding>
    </bindings>
</system.serviceModel>

创建服务实例的客户端方法

public static TServiceType GetServiceClient<TServiceType>(ConnStringsType connectionStringType, Page callingPage)
        where TServiceType : class
    {
        var spUrl = GetConnectionString(connectionStringType, callingPage);

    var result = new BasicHttpBinding(BasicHttpSecurityMode.None);            
        if(spUrl.ToLower().StartsWith("https"))
        {
            result = new BasicHttpBinding(BasicHttpSecurityMode.Transport);
        }            
        result.MaxReceivedMessageSize = int.MaxValue - 1;
        result.MaxBufferSize = int.MaxValue-1;
        if (!string.IsNullOrEmpty(spUrl))
        {
            return (TServiceType)Activator.CreateInstance(typeof(TServiceType), result, new EndpointAddress(spUrl));
        }
        return null;
    }
publicstatictservicetype GetServiceClient(ConnStringsType connectionStringType,Page callingPage)
其中TServiceType:class
{
var spUrl=GetConnectionString(ConnectionString类型,callingPage);
var结果=新的BasicHttpBinding(BasicHttpSecurityMode.None);
if(spul.ToLower().StartsWith(“https”))
{
结果=新的BasicHttpBinding(BasicHttpSecurityMode.Transport);
}            
result.MaxReceivedMessageSize=int.MaxValue-1;
result.MaxBufferSize=int.MaxValue-1;
如果(!string.IsNullOrEmpty(spUrl))
{
return(TServiceType)Activator.CreateInstance(typeof(TServiceType),result,newendpointAddress(spul));
}
返回null;
}
错误:

<system.serviceModel>
<services>
<service behaviorConfiguration="StandardServiceBehaviour" name="Thd.K2.Web.DataServicesLibrary.Common.Services.AdminService">

            <endpoint address="soap" binding="basicHttpBinding" name="AdminService" contract="Thd.K2.Web.DataServicesLibrary.Common.Interfaces.IAdminService" />
            <endpoint address="mex" binding="mexHttpBinding" name="Metadata" contract="IMetadataExchange" kind="mexEndpoint" endpointConfiguration="" />
        </service>
</services>
<behaviors>
    <serviceBehaviors>
          <behavior name="StandardServiceBehaviour">
                  <serviceMetadata httpsGetEnabled="false" />
                  <serviceDebug includeExceptionDetailInFaults="true" />
            </behavior>                
        </serviceBehaviors>
    </behaviors>
    <bindings>
        <basicHttpBinding>
            <binding name="customBinding" hostNameComparisonMode="StrongWildcard" receiveTimeout="00:10:00" sendTimeout="00:10:00" openTimeout="00:10:00" closeTimeout="00:10:00" maxReceivedMessageSize="1000000" maxBufferSize="1000000" maxBufferPoolSize="1000000" transferMode="Buffered" messageEncoding="Text" textEncoding="utf-8" bypassProxyOnLocal="false" useDefaultWebProxy="true">
                <readerQuotas maxDepth="2147483647" maxStringContentLength="214748364" maxArrayLength="2147483647" maxBytesPerRead="2147483647" maxNameTableCharCount="2147483647" />
                <security mode="Transport" />
            </binding>
        </basicHttpBinding>
        <webHttpBinding>
          <binding name="webBinding" bypassProxyOnLocal="true" useDefaultWebProxy="false" hostNameComparisonMode="WeakWildcard" sendTimeout="00:05:00" openTimeout="00:05:00" receiveTimeout="00:05:00" maxReceivedMessageSize="2147483647" maxBufferSize="2147483647" maxBufferPoolSize="2147483647">
            <readerQuotas maxArrayLength="2147483647" maxStringContentLength="2147483647" />
            <security mode="Transport">
            </security>
          </binding>
        </webHttpBinding>
    </bindings>
</system.serviceModel>
接收对的HTTP响应时出错。这可能是由于服务端点绑定未使用HTTP协议造成的。这也可能是由于服务器中止了HTTP请求上下文(可能是由于服务关闭)。有关详细信息,请参阅服务器日志。 堆栈:

服务器堆栈跟踪: 位于System.ServiceModel.Channels.HttpChannelUtilities.ProcessGetResponseWebException(WebException WebException、HttpWebRequest请求、HttpBortreason abortReason) 位于System.ServiceModel.Channels.HttpChannelFactory.HttpRequestChannel.HttpChannelRequest.WaitForReply(TimeSpan超时) 位于System.ServiceModel.Channels.RequestChannel.Request(消息消息,TimeSpan超时) 位于System.ServiceModel.Dispatcher.RequestChannelBinder.Request(消息消息,TimeSpan超时) 在System.ServiceModel.Channels.ServiceChannel.Call(字符串操作、布尔单向、ProxyOperationRuntime操作、对象[]输入、对象[]输出、时间跨度超时) 位于System.ServiceModel.Channels.ServiceChannelProxy.InvokeService(IMethodCallMessage方法调用,ProxyOperationRuntime操作) 位于System.ServiceModel.Channels.ServiceChannelProxy.Invoke(IMessage消息)

在[0]处重试异常: at System.Runtime.Remoting.Proxies.RealProxy.HandleReturnMessage(IMessage reqMsg,IMessage retMsg) at System.Runtime.Remoting.proxy.RealProxy.PrivateInvoke(MessageData&msgData,Int32类型) 在IAdminService.getBlackOutperiodByDescription(字符串lang,字符串描述) 位于AdminServiceClient.GetBlackOutperiodByDescription(字符串lang,字符串描述)
在EditBlackoutDates.LoadBlackout(字符串描述)

我认为这是关于属性的。是类似问题的答案。

@paramosh-非常感谢

这就成功了。作为其他参考,我实际上使用的是非RESTful WCF服务。因此,我对解决方案进行了如下修改 在web svc方法调用之前调用以下函数:

private void ExpandObjectGraphItems(AdminServiceClient svc)
    {
        var operations = svc.Endpoint.Contract.Operations;
        foreach (var operation in operations)
        {
            var dataContractBehavior = operation.Behaviors.Find<System.ServiceModel.Description.DataContractSerializerOperationBehavior>();
            if (dataContractBehavior != null)
            {
                dataContractBehavior.MaxItemsInObjectGraph = int.MaxValue;
            }
        }
    }
private void ExpandObjectGraphItems(AdminServiceClient svc)
{
var operations=svc.Endpoint.Contract.operations;
foreach(操作中的var操作)
{
var dataContractBehavior=operation.Behaviors.Find();
if(dataContractBehavior!=null)
{
dataContractBehavior.MaxItemsInObjectGraph=int.MaxValue;
}
}
}
在服务配置中添加了以下属性:

<behavior name="StandardServiceBehaviour">
                <dataContractSerializer maxItemsInObjectGraph="2147483646"/>


您是否按照错误消息所示检查了服务器日志?他们怎么说?我没有注意到服务端有任何错误/异常。