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?