0

I am calling a WCF service from a SharePoint site and getting an error on the client with below details, when relatively large object graph is returned.

On debugging the service I can see that is contructs the object correctly and the method returns the final object (that has the list of other objects) correctly. But I get exception on client side on the service method call.

Thie service/method works fine in most of the cases. Below are the service configurations (apologies for bad formatting)

Service Config:

<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>

Client method to create service instance

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;
    }

Error:

An error occurred while receiving the HTTP response to http://localhost:90/AdminService.svc/soap. This could be due to the service endpoint binding not using the HTTP protocol. This could also be due to an HTTP request context being aborted by the server (possibly due to the service shutting down). See server logs for more details. Stack:

Server stack trace: at System.ServiceModel.Channels.HttpChannelUtilities.ProcessGetResponseWebException(WebException webException, HttpWebRequest request, HttpAbortReason abortReason) at System.ServiceModel.Channels.HttpChannelFactory.HttpRequestChannel.HttpChannelRequest.WaitForReply(TimeSpan timeout) at System.ServiceModel.Channels.RequestChannel.Request(Message message, TimeSpan timeout) at System.ServiceModel.Dispatcher.RequestChannelBinder.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 IAdminService.GetBlackoutPeriodsByDescription(String lang, String description) at AdminServiceClient.GetBlackoutPeriodsByDescription(String lang, String description) at EditBlackoutDates.LoadBlackout(String description)

Vashu
  • 5
  • 2
  • 4

2 Answers2

0

I think this is about MaxItemsInObjectGraph property. Here is the answer to the similar problem.

Community
  • 1
  • 1
paramosh
  • 2,258
  • 1
  • 15
  • 23
0

@paramosh - Thanks a lot!!!

That did the trick. For others reference I was actually using a Non-RESTful WCF service. Hence I modified the solution as below Calling below function before the web svc method call:

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;
            }
        }
    }

Added following attribute to service config:

<behavior name="StandardServiceBehaviour">
                <dataContractSerializer maxItemsInObjectGraph="2147483646"/>
Vashu
  • 5
  • 2
  • 4