known-types

Two Interface and one concrete class in WCF

只愿长相守 提交于 2019-12-05 07:25:51
please check the below example namespace GServices { [ServiceKnownType(typeof(SearchType))] [ServiceContract(SessionMode = SessionMode.Allowed)] public interface ITest { [OperationContract] int subtract(int x, int y); } [ServiceKnownType(typeof(SearchType))] [ServiceContract(SessionMode = SessionMode.Allowed)] public interface ITest2 { [OperationContract] int add(int x, int y); } public class G : ITest2, ITest { public int add(int x, int y) { return x + y; } public int subtract(int x, int y) { return x + y; } } } ITest has subtract() method and Itest2 has add() method. Both are implemented by

How to specify a WCF known type in config that is generic?

你离开我真会死。 提交于 2019-12-03 07:43:39
问题 I have a type, let's call it Data<TKey> . I also have a WCF service contract that accepts a type (lets call it Wrapper ) with a property of type Object (for reasons I won't go into, this isn't optional). [DataContract] public class Data<TKey> { ... } [DataContract] public class Wrapper { [DataMember] public object DataItem { get; set; } } Right now I'm sending two classes IntData and LongData : [DataContract] public class IntData : Data<int> { /*empty*/ } [DataContract] public class LongData

What is the difference in WCF when using KnownType and ServiceKnownType?

风格不统一 提交于 2019-12-03 06:28:56
问题 I have a service that returns an array of animal but the list can contain cats, dogs, etc, which all extend animal. I know I need to use either the KnownType or ServiceKnownType attribute, and on the entity class or the service class, respectively. What is the difference between the 2 attributes? I prefer the ServiceKnownType because it is applied on the service, exactly where it is needed and called for, as opposed to KnownType which is applied on my entity. To me applying it on the entity

How to specify a WCF known type in config that is generic?

独自空忆成欢 提交于 2019-12-02 21:13:00
I have a type, let's call it Data<TKey> . I also have a WCF service contract that accepts a type (lets call it Wrapper ) with a property of type Object (for reasons I won't go into, this isn't optional). [DataContract] public class Data<TKey> { ... } [DataContract] public class Wrapper { [DataMember] public object DataItem { get; set; } } Right now I'm sending two classes IntData and LongData : [DataContract] public class IntData : Data<int> { /*empty*/ } [DataContract] public class LongData : Data<long> { /*empty*/ } They're both configured in the known types config file. The config resembles

What is the difference in WCF when using KnownType and ServiceKnownType?

倾然丶 夕夏残阳落幕 提交于 2019-12-02 19:03:05
I have a service that returns an array of animal but the list can contain cats, dogs, etc, which all extend animal. I know I need to use either the KnownType or ServiceKnownType attribute, and on the entity class or the service class, respectively. What is the difference between the 2 attributes? I prefer the ServiceKnownType because it is applied on the service, exactly where it is needed and called for, as opposed to KnownType which is applied on my entity. To me applying it on the entity class means knowing too far ahead how my entity class is being used. For now I have it on my entity and

Using Interfaces With WCF

守給你的承諾、 提交于 2019-12-01 22:01:47
I have Googled and read for hours now and I can't find anyone that deals with my specific scenario... I want to use interfaces in my WCF service contracts to loosely couple the service from the classes used on each end of the wire. This will enable us to have a low-level assembly that contains just the Service and Data Contracts (just interfaces) that we can hand to a consultant. On their end of the wire they can instantiate their data classes that implement our Data Contract interface, send it over the wire to us, and our WCF service will then translate/cast/whatever that incoming data into

Problem with knowntype attribute in wcf

混江龙づ霸主 提交于 2019-12-01 17:08:31
I'm having the following error in my wcf client. NetDispatcherFaultException was unhandled. The formatter threw an exception while trying to deserialize the message: There was an error while trying to deserialize parameter http://tempuri.org/:GetVehicleResult . The InnerException message was 'Error in line 1 position 266. Element ' http://tempuri.org/:GetVehicleResult ' contains data from a type that maps to the name ' http://schemas.datacontract.org/2004/07/WCFServer:Car '. The deserializer has no knowledge of any type that maps to this name. Consider using a DataContractResolver or add the

Generally accepted way to avoid KnownType attribute for every derived class

落花浮王杯 提交于 2019-11-28 21:20:30
Is there a generally accepted way to avoid having to use KnownType attributes on WCF services? I've been doing some research, and it looks like there are two options: Data contract resolver NetDataContractSerializer I'm not a big fan of having to statically add KnownType attributes every time I add a new type, hence wanting to avoid it. Is there a third option that should be used? If so, what is it? If not, which of the above two options are the right way to go? Edit - use a method A third option would be to use reflection [DataContract] [KnownType("DerivedTypes")] public abstract class

WCF Known Type from System.Object in Config

荒凉一梦 提交于 2019-11-27 22:23:02
问题 I'm trying to specify a known type in my config, but I'm having problems with the fact that it derives from Object. I can make it work specifying the known type via attribute. But in this case I need to make it work from the config. Here's an example. The following works fine: [ServiceContract] [ServiceKnownType(typeof(MyData))] public interface IContract { [OperationContract] void Send(object data); } [DataContract] public class MyData { [DataMember] public string Message { get; set; } } But

When is it appropriate to use the KnownType attribute?

£可爱£侵袭症+ 提交于 2019-11-27 08:12:28
After reading the MSDN reference, I still have questions about when to use the KnownType attribute. I understand that the attribute communicates type information to the serializer, but when is this needed? Is it appropriate when the class being serialized has references of a base class type, and there are up-cast derivative classes that could be set to those references? Moreover, are there any drawbacks to overusing the attribute? For instance, in the previous example, if the serialized class was marked with KnownType(baseClass) even though there was an explicit reference to that type?