2014-03-24 3 views
0

WCF 데이터 서비스 (현재 5.6)를 사용 중이며 열거 형이 지원되지 않기 때문에 (다른 이유로 인해) 제거 할 클라이언트 측 클래스에 몇 가지 추가 속성이 추가되었습니다. 예제 다음에 나오는 WritingEntity 이벤트를 사용하는 SaveChanges 중 http://blogs.msdn.com/b/phaniraj/archive/2008/12/11/customizing-serialization-of-entities-in-the-ado-net-data-services-client-library.aspxWCF 데이터 서비스 SaveChanges가 실행되지 않음 WritingEntity 이벤트

내 생성자가 이벤트를 첨부하지만 이벤트가 발생하고 때로는 그렇지 않은 경우가 더 많습니다.

public MyDataContext(System.Uri serviceRoot, bool ignoreProperties) 
    : this(serviceRoot) 
{ 
    if (ignoreProperties) 
     this.WritingEntity += EdiContext_WritingEntity; 
    this.SendingRequest2+=OnSendingRequest; 
} 

변경

SendingRequest2 이벤트가 화재, 나는 여러 데이터

private void OnSendingRequest(object sender, SendingRequest2EventArgs e) 
{ 
    e.RequestMessage.SetHeader("profile", ClientSettings.Instance.Profile); 
} 

사람이 알고 있나요을 지원하기 위해 요청에 몇 가지 헤더 정보를 첨부하는 데 사용합니까

db.AttachTo("Maps", map, "*"); 
db.UpdateObject(map); 
ProcessMapCoordinates(db, map); 
ProcessModifiers(map, db); 
db.SaveChanges(); 

를 저장하려면 어떤 상황에서 WritingEntity 이벤트가 실행되지 않습니까?

부분 클래스의 확장 속성이 직렬화되지 않도록 다른 방법이 있습니까?

감사

답변

0

이가 클라이언트 측 부분 클래스의 공공 열거 형의 사용에 의해 발생했다 나타납니다. 열거 형의 액세스 한정자를 내부로 변경하면 문제가 사라졌습니다.

if (ignoreProperties) 
{ 
    this.Configurations.RequestPipeline.OnEntryStarting((a => 
    { 
     entityType = Type.GetType(a.Entry.TypeName); 
     if (entityType != null) 
     { 
      var props = 
       entityType.GetProperties() 
        .Where(
         property => 
          property.GetCustomAttributes(typeof (DoNotSerializeAttribute), false).Length > 0) 
        .Select(p => p.Name) 
        .ToArray(); 
      a.Entry.RemoveProperties(props); 
     } 
    })); 
} 
: 과정에서

나는 속성이 RequestPipeline 이벤트에 후킹하여 직렬화 무엇인지 제어하는 ​​더 나은 방법을 배웠습니다