TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
ragavan e
NA
8
959
Unable to serialize while using Encoding as DataMember in WCF services
Aug 8 2020 3:11 AM
Hi,
In WCF services in Datacontract ,I am using Encoding as datamember . This is my service code .
[ServiceContract]
public
interface
IService1
{
[OperationContract]
void
GetData(CompositeType compositeType);
}
[DataContract]
public
class
CompositeType
{
[DataMember]
public
Encoding MessageEncoding
{
get
;
set
;
}
}
}
Client code :
EndpointAddress addr =
new
EndpointAddress(
"net.pipe://localhost/Service1"
);
ChannelFactory<IService1> chn =
new
ChannelFactory<IService1>(netNamedPipeBinding, addr);
service1 = chn.CreateChannel();CompositeType wcfFor =
new
CompositeType
{
MessageEncoding = Encoding.UTF8,
};
service1.GetData(wcfFor);
When I tried to hit the service from client ,I am getting below exception
There was an error while trying to serialize parameter http://tempuri.org/:compositeType. The InnerException message was 'Type 'System.Text.UTF8Encoding' with data contract name 'UTF8Encoding:http://schemas.datacontract.org/2004/07/System.Text' is not expected. Consider using a DataContractResolver if you are using DataContractSerializer or add any types not known statically to the list of known types - for example, by using the KnownTypeAttribute attribute or by adding them to the list of known types passed to the serializer.'. Please see InnerException for more details.
I have also tried by using knowntype attribute and datacontract resolver . Still I am facing this same issue
Can we use Encoding as datamember in WCF service?
Reply
Answers (
1
)
How to push data from WCF service to client applications
Pass EndpointAddress to ChannelFactory with EndPointConfigName