2012-03-28 31 views
0

当我打电话从SharePoint网站上的WCF服务,并得到一个错误的客户端上使用下面的细节,当返回比较大的对象图。模糊WCF错误处理大量的对象图

在调试我可以看到,是服务正确contructs对象和方法返回最终对象(即具有其它对象的列表)正确。但是我在服务方法调用的客户端发生异常。

你的服务/方法在大多数情况下都能正常工作。下面是该服务的配置(道歉坏格式)

服务配置:

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

错误:

错误占有在接收到对http://localhost:90/AdminService.svc/soap的HTTP响应的同时,这可能是由于服务端点绑定不使用HTTP协议。这也可能是由于HTTP请求上下文被服务器中止(可能是由于服务关闭)。查看服务器日志获取更多详细信 堆栈:

服务器堆栈跟踪: 在System.ServiceModel.Channels.HttpChannelUtilities.ProcessGetResponseWebException(引发WebException引发WebException,HttpWebRequest的请求,HttpAbortReason abortReason) 在System.ServiceModel.Channels.HttpChannelFactory.HttpRequestChannel.HttpChannelRequest.WaitForReply(时间跨度超时) 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操作,单向布尔值,ProxyOperationRuntime操作,Object [] ins,Object []输出,TimeSpan超时) 在System.ServiceModel.Channels.ServiceChannelProxy.InvokeService(IMethodCallMessage包括MethodCall,ProxyOperationRuntime操作) 在System.ServiceModel.Channels.ServiceChannelProxy.Invoke(即时聊天消息)[0]时

异常重新抛出: 在System.Runtime。 Remoting.Proxies.RealProxy.HandleReturnMessage(即时聊天reqMsg,即时聊天retMsg) 在System.Runtime.Remoting.Proxies.RealProxy.PrivateInvoke(MessageData & MSGDATA,的Int32类型) 在IAdminService.GetBlackoutPeriodsByDescription(字符串郎,字符串描述) 在AdminServiceClient .GetBlackoutPeriodsByDescription(String lang,字符串描述) at EditBlackoutDates.LoadBlackout(String descriptio n)

+0

你检查服务器日志类似错误信息提示?他们说什么? – Randolpho 2012-03-28 15:34:58

+0

我无法注意到服务端的任何错误/异常。 – Vashu 2012-03-29 11:39:05

回答

0

@paramosh - 非常感谢!

这样做。对于其他人参考,我实际上使用了非RESTful WCF服务。因此,我修改了解决方案如下 网络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; 
      } 
     } 
    } 

添加以下属性服务配置:

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