向DataContract List添加新项目时的错误异常<t>

时间:2017-10-25 12:41:33

标签: c# wcf xml-serialization

我使用来自另一个wcf-service的数据协定来代理wcf-service,目的是修改或附加对象。

在某些情况下,我注意到一些错误,协议在通过代理调用时会产生异常,但不会直接在直接的wcf服务上。

调查问题,我注意到一些(对我来说)收集更改的奇怪行为:

当我清理集合或从集合中删除项目时,它仍然可以正确地返回结果。只要我尝试添加到集合中,它就会在序列化后返回FaultException:

<s:Fault>
     <faultcode xmlns:a="http://schemas.microsoft.com/net/2005/12/windowscommunicationfoundation/dispatcher">a:InternalServiceFault</faultcode>
     <faultstring xml:lang="nl-NL">Message is closed.</faultstring>
     <detail>
        <ExceptionDetail xmlns="http://schemas.datacontract.org/2004/07/System.ServiceModel" xmlns:i="http://www.w3.org/2001/XMLSchema-instance">
           <HelpLink i:nil="true"/>
           <InnerException i:nil="true"/>
           <Message>Message is closed.</Message>
           <StackTrace>at 
System.ServiceModel.Channels.BodyWriterMessage.get_Properties()
at System.ServiceModel.Channels.CorrelationCallbackMessageProperty.TryGet(Message message, CorrelationCallbackMessageProperty&amp; property)
at System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.FinalizeCorrelation(MessageRpc&amp; rpc)   at System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage8(MessageRpc&amp; rpc)   at System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage5(MessageRpc&amp; rpc)   at System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage11(MessageRpc&amp; rpc)   at System.ServiceModel.Dispatcher.MessageRpc.Process(Boolean isOperationContextSet)</StackTrace>
           <Type>System.ObjectDisposedException</Type>
        </ExceptionDetail>
     </detail>
  </s:Fault>

示例:

[DataContract]
public class AgreementDto
{
    [DataMember]
    public List<AgreementDto> Children;

当我调用agreement.Children.Clean()时,它可以工作,但是当我尝试使用agreement.Children.Add(new AgreementDto())时,它只能在调试中工作,直到它序列化。

当我在代码中创建并调用ServiceClient时(当然)。

代码

 public class AgreementService : BaseWcfServices
    {
          private readonly IProxyFactory<IAgreementsService> agreementsServiceProxyFactory;

           public AgreementService(IProxyFactory<IAgreementsService> agreementsServiceProxyFactory)

         {
            this.agreementsServiceProxyFactory= agreementsServiceProxyFactory
         }

        public AgreementDto GetAgreement(string agreementReference)
        {
                var agreement = agreementsServiceProxyFactory.Create().GetAgreement(agreementReference);

                agreement.Children.Add(new AgreementDto());

                return agreement
        }
    }

1 个答案:

答案 0 :(得分:0)

问题解决了。显然,ApplicationInsight吞下REAL异常并重新抛出它自己的异常。在这种情况下非常混乱,但在本地使用SDK时解决了。