-
June 12th, 2009, 05:10 PM
#1
WCF exception
Hi all,
I am developing a WCF application and i can send simple DataContract classes without problems. But when i try to send a class having a different type of class as a field, i get CommunicationException. Class structure is like below;
Code:
[DataContract]
public class ClassA
{
[DataMember]
public ClassB myObject1;
[DataMember]
public ClassC myObject2;
}
And i also defined both ClassB and ClassC as DataContract. I don't know if i am doing something wrong. Any help would be appreciated.
-
June 13th, 2009, 10:28 AM
#2
Re: WCF exception
what is the message and innerexception of the CommuncationException.
Sound like you did the correct thing, but without any more information about the exception, we can't help you
-
June 15th, 2009, 07:51 AM
#3
Re: WCF exception
Thanks for the reply Danny,
The reason of the CommunicationException seems that WCF cannot serialize the class B and class C objects in class A. I made some search and found out that i should use Surrogates to resolve that problem to make those classes serializable. But it requires much work to do that since if i use Surrogates i need to create Surrogate classes for class A and B to make them known types for the WCF service. And i found another thing showing that we can use KnownType or ServiceKnownType attributes for those inner class objects but all examples about those attributes are implemented on base class objects such as using a base Person class for both Employee and Employer classes.
Is there any other way to manage that.
Thanks in advance
Originally Posted by dannystommen
what is the message and innerexception of the CommuncationException.
Sound like you did the correct thing, but without any more information about the exception, we can't help you
-
June 15th, 2009, 08:26 AM
#4
Re: WCF exception
Following is a codesnippet from my own project, which works fine only using DataContract and DataMember attributes.
Code:
[DataContract]
public class User {
[DataMember]
public int ID {
...
}
[DataMember]
public string Username {
...
}
[DataMember]
public UserRole UserRole {
...
}
}
[DataContract]
public class UserRole {
[DataMember]
public int ID {
...
}
[DataMember]
public string Description {
...
}
}
As you can see, it has the same syntax as your example. I don't use Surrogates or (Service)KnownType, and it works just fine.
The reason of the CommunicationException seems that WCF cannot serialize the class B and class C objects in class A
Can you please quote the CommuncationException (message and innerexception), instead of saying only what is causing it.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|