2012-02-20 2 views
0

wcf에서 클래스를 보내려고하는데이 클래스를 System.Windows.Media.Media3D.Vector3d 직렬화하는 데 문제가 있습니다. 이 예외가 발생합니다wcf 호출시 System.Windows.Media.Media.Media.Media3D.Vector3d 직렬화에 대한 예외

매개 변수 WEntityService : iState를 직렬화하는 동안 오류가 발생했습니다. InnerException 메시지가 'System.Windows.Media.Media3D.Vector3D'형식으로 데이터 계약 이름이 인 'Vector3D : http : //schemas.datacontract.org/2004/07/System.Windows.Media.Media3D'가 아닙니다. 예상했다. 을 DataContractResolver를 사용하거나 알려진 유형 목록에 정적으로 알려지지 않은 유형을 추가하십시오 (예 : ). KnownTypeAttribute 속성을 사용하거나 DataContractSerializer에 전달 된 알려진 유형 목록에 추가하십시오. '
자세한 내용은 InnerException을 참조하십시오. MSDN 웹 사이트 http://msdn.microsoft.com/en-us/library/ms606682.aspx

[DataContract] 
    public ref class WData 
    { 
    public: 
    WData(); 

    [DataMember] 
    Vector3D^ mLinearVelocity; 

    [DataMember] 
    System::String^ mName; 
    }; 

WData::WData() 
    : mLinearVelocity(gcnew Vector3D(0.0, 0.0, 0.0))   
    , mName(gcnew System::String(' ', 1)) 
    { 

    } 

, 당신은 값 Vector3D 직렬화 attiribute을 가지고 있음을 알 수있다. wcf serialisable 형식의 경우이 웹 페이지를 참조하십시오. http://msdn.microsoft.com/en-us/library/ms731923.aspx Vector3D는 wcf에 대해 serialize 가능해야합니다. 누군가 직렬화되지 않은 이유를 설명 할 수 있습니까? Thks.

답변

0

알려진 유형의 목록에 Vector3D를 추가 할 수 있습니까? 데이터 계약 수준에서 아래 예를 참조하십시오. 나는 그것이 당신의 문제를 해결해야한다고 생각합니다.

[DataContract] 
public class Book { } 

[DataContract] 
public class Magazine { } 

[DataContract] 
[KnownType(typeof(Book))] 
[KnownType(typeof(Magazine))] 
public class LibraryCatalog 
{ 
    [DataMember] 
    System.Collections.Hashtable theCatalog; 
} 

당신은 데이터 계약 수준에서 알려진 유형을 추가하고, 아래처럼 뭔가를 할 수있는 서비스 만 계약 수준에서 추가 할 수없는 경우는 - A [ServiceKnownTypeAttribute] 추가!

// Apply the ServiceKnownTypeAttribute to the 
// interface specifying the type to include. Apply 
// the attribute more than once if needed. 
[ServiceKnownType(typeof(Widget))] 
[ServiceKnownType(typeof(Machine))] 
[ServiceContract()] 
public interface ICatalog2 
{ 
    // Any object type can be inserted into a Hashtable. The 
    // ServiceKnownTypeAttribute allows you to include those types 
    // with the client code. 
    [OperationContract] 
    Hashtable GetItems(); 
}